diff mbox

[ovs-dev] socket-util-unix: Avoid buffer read overrun in get_unix_name_len().

Message ID 1473910743-26204-1-git-send-email-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff Sept. 15, 2016, 3:39 a.m. UTC
If the socket length does not include any of the bytes of the path, then
the code should not read even the first byte of the path.

Found by valgrind.

CC: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
Reported-by: Joe Stringer <joe@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/socket-util-unix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Thadeu Lima de Souza Cascardo Sept. 15, 2016, 12:38 p.m. UTC | #1
On Wed, Sep 14, 2016 at 08:39:03PM -0700, Ben Pfaff wrote:
> If the socket length does not include any of the bytes of the path, then
> the code should not read even the first byte of the path.
> 
> Found by valgrind.
> 
> CC: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
> Reported-by: Joe Stringer <joe@ovn.org>
> Signed-off-by: Ben Pfaff <blp@ovn.org>

Acked-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>

> ---
>  lib/socket-util-unix.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/socket-util-unix.c b/lib/socket-util-unix.c
> index 5d4b88c..59f63fc 100644
> --- a/lib/socket-util-unix.c
> +++ b/lib/socket-util-unix.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (c) 2014 Nicira, Inc.
> + * Copyright (c) 2014, 2016 Nicira, Inc.
>   *
>   * Licensed under the Apache License, Version 2.0 (the "License");
>   * you may not use this file except in compliance with the License.
> @@ -389,7 +389,7 @@ error:
>  int
>  get_unix_name_len(const struct sockaddr_un *sun, socklen_t sun_len)
>  {
> -    return (sun_len >= offsetof(struct sockaddr_un, sun_path) &&
> +    return (sun_len > offsetof(struct sockaddr_un, sun_path) &&
>              sun->sun_path[0] != 0
>              ? sun_len - offsetof(struct sockaddr_un, sun_path)
>              : 0);
> -- 
> 2.1.3
>
Joe Stringer Sept. 15, 2016, 5:27 p.m. UTC | #2
On 14 September 2016 at 20:39, Ben Pfaff <blp@ovn.org> wrote:
> If the socket length does not include any of the bytes of the path, then
> the code should not read even the first byte of the path.
>
> Found by valgrind.
>
> CC: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
> Reported-by: Joe Stringer <joe@ovn.org>
> Signed-off-by: Ben Pfaff <blp@ovn.org>

Thanks.

Acked-by: Joe Stringer <joe@ovn.org>
Ben Pfaff Sept. 15, 2016, 5:41 p.m. UTC | #3
On Thu, Sep 15, 2016 at 10:27:09AM -0700, Joe Stringer wrote:
> On 14 September 2016 at 20:39, Ben Pfaff <blp@ovn.org> wrote:
> > If the socket length does not include any of the bytes of the path, then
> > the code should not read even the first byte of the path.
> >
> > Found by valgrind.
> >
> > CC: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
> > Reported-by: Joe Stringer <joe@ovn.org>
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> 
> Thanks.
> 
> Acked-by: Joe Stringer <joe@ovn.org>

Thanks Joe and Thadeu, I applied this to master and branch-2.6.
diff mbox

Patch

diff --git a/lib/socket-util-unix.c b/lib/socket-util-unix.c
index 5d4b88c..59f63fc 100644
--- a/lib/socket-util-unix.c
+++ b/lib/socket-util-unix.c
@@ -1,5 +1,5 @@ 
 /*
- * Copyright (c) 2014 Nicira, Inc.
+ * Copyright (c) 2014, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -389,7 +389,7 @@  error:
 int
 get_unix_name_len(const struct sockaddr_un *sun, socklen_t sun_len)
 {
-    return (sun_len >= offsetof(struct sockaddr_un, sun_path) &&
+    return (sun_len > offsetof(struct sockaddr_un, sun_path) &&
             sun->sun_path[0] != 0
             ? sun_len - offsetof(struct sockaddr_un, sun_path)
             : 0);