All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect
@ 2017-05-24 10:26 Mateusz Jurczyk
  2017-05-24 16:58   ` Kees Cook
  2017-06-22 22:27 ` Samuel Ortiz
  0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Jurczyk @ 2017-05-24 10:26 UTC (permalink / raw)
  To: Samuel Ortiz, David S. Miller
  Cc: linux-wireless, netdev, linux-kernel, security

Fix the sockaddr length verification in the connect() handler of NFC/LLCP
sockets, to compare against the size of the actual structure expected on
input (sockaddr_nfc_llcp) instead of its shorter version (sockaddr_nfc).

Both structures are defined in include/uapi/linux/nfc.h. The fields
specific to the _llcp extended struct are as follows:

   276		__u8 dsap; /* Destination SAP, if known */
   277		__u8 ssap; /* Source SAP to be bound to */
   278		char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
   279		size_t service_name_len;

If the caller doesn't provide a sufficiently long sockaddr buffer, these
fields remain uninitialized (and they currently originate from the stack
frame of the top-level sys_connect handler). They are then copied by
llcp_sock_connect() into internal storage (nfc_llcp_sock structure), and
could be subsequently read back through the user-mode getsockname()
function (handled by llcp_sock_getname()). This would result in the
disclosure of up to ~70 uninitialized bytes from the kernel stack to
user-mode clients capable of creating AFC_NFC sockets.

Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com>
---
 net/nfc/llcp_sock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 2ffb18e73df6..d0d12bea65cb 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -662,8 +662,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
 
 	pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
 
-	if (!addr || len < sizeof(struct sockaddr_nfc) ||
-	    addr->sa_family != AF_NFC)
+	if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC)
 		return -EINVAL;
 
 	if (addr->service_name_len == 0 && addr->dsap == 0)
-- 
2.13.0.219.gdb65acc882-goog

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect
@ 2017-05-24 16:58   ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2017-05-24 16:58 UTC (permalink / raw)
  To: Mateusz Jurczyk
  Cc: Samuel Ortiz, David S. Miller, linux-wireless,
	Network Development, LKML, security

On Wed, May 24, 2017 at 3:26 AM, Mateusz Jurczyk <mjurczyk@google.com> wrote:
> Fix the sockaddr length verification in the connect() handler of NFC/LLCP
> sockets, to compare against the size of the actual structure expected on
> input (sockaddr_nfc_llcp) instead of its shorter version (sockaddr_nfc).
>
> Both structures are defined in include/uapi/linux/nfc.h. The fields
> specific to the _llcp extended struct are as follows:
>
>    276          __u8 dsap; /* Destination SAP, if known */
>    277          __u8 ssap; /* Source SAP to be bound to */
>    278          char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
>    279          size_t service_name_len;
>
> If the caller doesn't provide a sufficiently long sockaddr buffer, these
> fields remain uninitialized (and they currently originate from the stack
> frame of the top-level sys_connect handler). They are then copied by
> llcp_sock_connect() into internal storage (nfc_llcp_sock structure), and
> could be subsequently read back through the user-mode getsockname()
> function (handled by llcp_sock_getname()). This would result in the
> disclosure of up to ~70 uninitialized bytes from the kernel stack to
> user-mode clients capable of creating AFC_NFC sockets.
>
> Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com>

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  net/nfc/llcp_sock.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
> index 2ffb18e73df6..d0d12bea65cb 100644
> --- a/net/nfc/llcp_sock.c
> +++ b/net/nfc/llcp_sock.c
> @@ -662,8 +662,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
>
>         pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
>
> -       if (!addr || len < sizeof(struct sockaddr_nfc) ||
> -           addr->sa_family != AF_NFC)
> +       if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC)
>                 return -EINVAL;
>
>         if (addr->service_name_len == 0 && addr->dsap == 0)
> --
> 2.13.0.219.gdb65acc882-goog
>



-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect
@ 2017-05-24 16:58   ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2017-05-24 16:58 UTC (permalink / raw)
  To: Mateusz Jurczyk
  Cc: Samuel Ortiz, David S. Miller, linux-wireless,
	Network Development, LKML, security-DgEjT+Ai2ygdnm+yROfE0A

On Wed, May 24, 2017 at 3:26 AM, Mateusz Jurczyk <mjurczyk-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> wrote:
> Fix the sockaddr length verification in the connect() handler of NFC/LLCP
> sockets, to compare against the size of the actual structure expected on
> input (sockaddr_nfc_llcp) instead of its shorter version (sockaddr_nfc).
>
> Both structures are defined in include/uapi/linux/nfc.h. The fields
> specific to the _llcp extended struct are as follows:
>
>    276          __u8 dsap; /* Destination SAP, if known */
>    277          __u8 ssap; /* Source SAP to be bound to */
>    278          char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
>    279          size_t service_name_len;
>
> If the caller doesn't provide a sufficiently long sockaddr buffer, these
> fields remain uninitialized (and they currently originate from the stack
> frame of the top-level sys_connect handler). They are then copied by
> llcp_sock_connect() into internal storage (nfc_llcp_sock structure), and
> could be subsequently read back through the user-mode getsockname()
> function (handled by llcp_sock_getname()). This would result in the
> disclosure of up to ~70 uninitialized bytes from the kernel stack to
> user-mode clients capable of creating AFC_NFC sockets.
>
> Signed-off-by: Mateusz Jurczyk <mjurczyk-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

Acked-by: Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

-Kees

> ---
>  net/nfc/llcp_sock.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
> index 2ffb18e73df6..d0d12bea65cb 100644
> --- a/net/nfc/llcp_sock.c
> +++ b/net/nfc/llcp_sock.c
> @@ -662,8 +662,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
>
>         pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
>
> -       if (!addr || len < sizeof(struct sockaddr_nfc) ||
> -           addr->sa_family != AF_NFC)
> +       if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC)
>                 return -EINVAL;
>
>         if (addr->service_name_len == 0 && addr->dsap == 0)
> --
> 2.13.0.219.gdb65acc882-goog
>



-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect
  2017-05-24 10:26 [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect Mateusz Jurczyk
  2017-05-24 16:58   ` Kees Cook
@ 2017-06-22 22:27 ` Samuel Ortiz
  1 sibling, 0 replies; 4+ messages in thread
From: Samuel Ortiz @ 2017-06-22 22:27 UTC (permalink / raw)
  To: Mateusz Jurczyk
  Cc: David S. Miller, linux-wireless, netdev, linux-kernel, security

Hi Mateusz,

On Wed, May 24, 2017 at 12:26:20PM +0200, Mateusz Jurczyk wrote:
> Fix the sockaddr length verification in the connect() handler of NFC/LLCP
> sockets, to compare against the size of the actual structure expected on
> input (sockaddr_nfc_llcp) instead of its shorter version (sockaddr_nfc).
> 
> Both structures are defined in include/uapi/linux/nfc.h. The fields
> specific to the _llcp extended struct are as follows:
> 
>    276		__u8 dsap; /* Destination SAP, if known */
>    277		__u8 ssap; /* Source SAP to be bound to */
>    278		char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
>    279		size_t service_name_len;
> 
> If the caller doesn't provide a sufficiently long sockaddr buffer, these
> fields remain uninitialized (and they currently originate from the stack
> frame of the top-level sys_connect handler). They are then copied by
> llcp_sock_connect() into internal storage (nfc_llcp_sock structure), and
> could be subsequently read back through the user-mode getsockname()
> function (handled by llcp_sock_getname()). This would result in the
> disclosure of up to ~70 uninitialized bytes from the kernel stack to
> user-mode clients capable of creating AFC_NFC sockets.
> 
> Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com>
> ---
>  net/nfc/llcp_sock.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
Applied to nfc-next, thanks.

Cheers,
Samuel.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-22 22:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 10:26 [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect Mateusz Jurczyk
2017-05-24 16:58 ` Kees Cook
2017-05-24 16:58   ` Kees Cook
2017-06-22 22:27 ` Samuel Ortiz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.