diff mbox series

[v2,2/4] CVE-2022-23219: Buffer overflow in sunrpc clnt_create for "unix" (bug 22542)

Message ID aafa82f116bad4d781e66751177cdd4995eb7c07.1642148513.git.fweimer@redhat.com
State Committed
Commit 226b46770c82899b555986583294b049c6ec9b40
Headers show
Series CVE-2022-23218, CVE-2022-23219: sunrpc buffer overflows | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Florian Weimer Jan. 14, 2022, 8:24 a.m. UTC
Processing an overlong pathname in the sunrpc clnt_create function
results in a stack-based buffer overflow.
---
 NEWS              |  4 +++-
 sunrpc/clnt_gen.c | 10 +++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

Comments

Siddhesh Poyarekar Jan. 17, 2022, 3:29 a.m. UTC | #1
On 14/01/2022 13:54, Florian Weimer via Libc-alpha wrote:
> Processing an overlong pathname in the sunrpc clnt_create function
> results in a stack-based buffer overflow.
> ---
>   NEWS              |  4 +++-
>   sunrpc/clnt_gen.c | 10 +++++++---
>   2 files changed, 10 insertions(+), 4 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
> diff --git a/NEWS b/NEWS
> index a957b19fdc..94248b580d 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -150,7 +150,9 @@ Changes to build and runtime requirements:
>   
>   Security related changes:
>   
> -  [Add security related changes here]
> +  CVE-2022-23219: Passing an overlong file name to the clnt_create
> +  legacy function could result in a stack-based buffer overflow when
> +  using the "unix" protocol.  Reported by Martin Sebor.
>   
>   The following bugs are resolved with this release:
>   
> diff --git a/sunrpc/clnt_gen.c b/sunrpc/clnt_gen.c
> index 13ced8994e..b44357cd88 100644
> --- a/sunrpc/clnt_gen.c
> +++ b/sunrpc/clnt_gen.c
> @@ -57,9 +57,13 @@ clnt_create (const char *hostname, u_long prog, u_long vers,
>   
>     if (strcmp (proto, "unix") == 0)
>       {
> -      memset ((char *)&sun, 0, sizeof (sun));
> -      sun.sun_family = AF_UNIX;
> -      strcpy (sun.sun_path, hostname);
> +      if (__sockaddr_un_set (&sun, hostname) < 0)
> +	{
> +	  struct rpc_createerr *ce = &get_rpc_createerr ();
> +	  ce->cf_stat = RPC_SYSTEMERROR;
> +	  ce->cf_error.re_errno = errno;
> +	  return NULL;
> +	}
>         sock = RPC_ANYSOCK;
>         client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
>         if (client == NULL)
diff mbox series

Patch

diff --git a/NEWS b/NEWS
index a957b19fdc..94248b580d 100644
--- a/NEWS
+++ b/NEWS
@@ -150,7 +150,9 @@  Changes to build and runtime requirements:
 
 Security related changes:
 
-  [Add security related changes here]
+  CVE-2022-23219: Passing an overlong file name to the clnt_create
+  legacy function could result in a stack-based buffer overflow when
+  using the "unix" protocol.  Reported by Martin Sebor.
 
 The following bugs are resolved with this release:
 
diff --git a/sunrpc/clnt_gen.c b/sunrpc/clnt_gen.c
index 13ced8994e..b44357cd88 100644
--- a/sunrpc/clnt_gen.c
+++ b/sunrpc/clnt_gen.c
@@ -57,9 +57,13 @@  clnt_create (const char *hostname, u_long prog, u_long vers,
 
   if (strcmp (proto, "unix") == 0)
     {
-      memset ((char *)&sun, 0, sizeof (sun));
-      sun.sun_family = AF_UNIX;
-      strcpy (sun.sun_path, hostname);
+      if (__sockaddr_un_set (&sun, hostname) < 0)
+	{
+	  struct rpc_createerr *ce = &get_rpc_createerr ();
+	  ce->cf_stat = RPC_SYSTEMERROR;
+	  ce->cf_error.re_errno = errno;
+	  return NULL;
+	}
       sock = RPC_ANYSOCK;
       client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
       if (client == NULL)