* [PATCH v2 net] nfc: close a race condition in llcp_sock_getname()
@ 2016-01-29 19:37 Cong Wang
2016-02-24 18:54 ` Cong Wang
2016-02-25 7:43 ` Samuel Ortiz
0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2016-01-29 19:37 UTC (permalink / raw)
To: netdev-u79uwXL29TY76Z2rM5mHXA
Cc: dvyukov-hpIqsD4AKlfQT0dZR+AlfA,
linux-wireless-u79uwXL29TY76Z2rM5mHXA, Cong Wang,
Lauro Ramos Venancio, Aloisio Almeida Jr, Samuel Ortiz
llcp_sock_getname() checks llcp_sock->dev to make sure
llcp_sock is already connected or bound, however, we could
be in the middle of llcp_sock_bind() where llcp_sock->dev
is bound and llcp_sock->service_name_len is set,
but llcp_sock->service_name is not, in this case we would
lead to copy some bytes from a NULL pointer.
Just lock the sock since this is not a hot path anyway.
Reported-by: Dmitry Vyukov <dvyukov-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: Lauro Ramos Venancio <lauro.venancio-430g2QfJUUCGglJvpFV4uA@public.gmane.org>
Cc: Aloisio Almeida Jr <aloisio.almeida-430g2QfJUUCGglJvpFV4uA@public.gmane.org>
Cc: Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Signed-off-by: Cong Wang <xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
net/nfc/llcp_sock.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index ecf0a01..b9edf5f 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -509,6 +509,11 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
memset(llcp_addr, 0, sizeof(*llcp_addr));
*len = sizeof(struct sockaddr_nfc_llcp);
+ lock_sock(sk);
+ if (!llcp_sock->dev) {
+ release_sock(sk);
+ return -EBADFD;
+ }
llcp_addr->sa_family = AF_NFC;
llcp_addr->dev_idx = llcp_sock->dev->idx;
llcp_addr->target_idx = llcp_sock->target_idx;
@@ -518,6 +523,7 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
llcp_addr->service_name_len = llcp_sock->service_name_len;
memcpy(llcp_addr->service_name, llcp_sock->service_name,
llcp_addr->service_name_len);
+ release_sock(sk);
return 0;
}
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net] nfc: close a race condition in llcp_sock_getname()
2016-01-29 19:37 [PATCH v2 net] nfc: close a race condition in llcp_sock_getname() Cong Wang
@ 2016-02-24 18:54 ` Cong Wang
2016-02-25 7:43 ` Samuel Ortiz
1 sibling, 0 replies; 3+ messages in thread
From: Cong Wang @ 2016-02-24 18:54 UTC (permalink / raw)
To: Linux Kernel Network Developers
Cc: Dmitry Vyukov, linux-wireless, Cong Wang, Lauro Ramos Venancio,
Aloisio Almeida Jr, Samuel Ortiz
On Fri, Jan 29, 2016 at 11:37 AM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> llcp_sock_getname() checks llcp_sock->dev to make sure
> llcp_sock is already connected or bound, however, we could
> be in the middle of llcp_sock_bind() where llcp_sock->dev
> is bound and llcp_sock->service_name_len is set,
> but llcp_sock->service_name is not, in this case we would
> lead to copy some bytes from a NULL pointer.
>
> Just lock the sock since this is not a hot path anyway.
>
> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> Cc: Lauro Ramos Venancio <lauro.venancio@openbossa.org>
> Cc: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
> Cc: Samuel Ortiz <sameo@linux.intel.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Samuel, please take a look at this one too.
> ---
> net/nfc/llcp_sock.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
> index ecf0a01..b9edf5f 100644
> --- a/net/nfc/llcp_sock.c
> +++ b/net/nfc/llcp_sock.c
> @@ -509,6 +509,11 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
> memset(llcp_addr, 0, sizeof(*llcp_addr));
> *len = sizeof(struct sockaddr_nfc_llcp);
>
> + lock_sock(sk);
> + if (!llcp_sock->dev) {
> + release_sock(sk);
> + return -EBADFD;
> + }
> llcp_addr->sa_family = AF_NFC;
> llcp_addr->dev_idx = llcp_sock->dev->idx;
> llcp_addr->target_idx = llcp_sock->target_idx;
> @@ -518,6 +523,7 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
> llcp_addr->service_name_len = llcp_sock->service_name_len;
> memcpy(llcp_addr->service_name, llcp_sock->service_name,
> llcp_addr->service_name_len);
> + release_sock(sk);
>
> return 0;
> }
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net] nfc: close a race condition in llcp_sock_getname()
2016-01-29 19:37 [PATCH v2 net] nfc: close a race condition in llcp_sock_getname() Cong Wang
2016-02-24 18:54 ` Cong Wang
@ 2016-02-25 7:43 ` Samuel Ortiz
1 sibling, 0 replies; 3+ messages in thread
From: Samuel Ortiz @ 2016-02-25 7:43 UTC (permalink / raw)
To: Cong Wang
Cc: netdev, dvyukov, linux-wireless, Lauro Ramos Venancio,
Aloisio Almeida Jr
Hi Cong,
On Fri, Jan 29, 2016 at 11:37:40AM -0800, Cong Wang wrote:
> llcp_sock_getname() checks llcp_sock->dev to make sure
> llcp_sock is already connected or bound, however, we could
> be in the middle of llcp_sock_bind() where llcp_sock->dev
> is bound and llcp_sock->service_name_len is set,
> but llcp_sock->service_name is not, in this case we would
> lead to copy some bytes from a NULL pointer.
>
> Just lock the sock since this is not a hot path anyway.
>
> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> Cc: Lauro Ramos Venancio <lauro.venancio@openbossa.org>
> Cc: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
> Cc: Samuel Ortiz <sameo@linux.intel.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> net/nfc/llcp_sock.c | 6 ++++++
> 1 file changed, 6 insertions(+)
Applied as well, thanks.
Cheers,
Samuel.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-25 7:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-29 19:37 [PATCH v2 net] nfc: close a race condition in llcp_sock_getname() Cong Wang
2016-02-24 18:54 ` Cong Wang
2016-02-25 7:43 ` Samuel Ortiz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).