* [Patch net] nfc: use GFP_USER for user-controlled kmalloc @ 2016-01-02 0:34 Cong Wang 2016-01-02 0:34 ` [Patch net] nfc: check sock state in llcp_sock_getname() Cong Wang 0 siblings, 1 reply; 4+ messages in thread From: Cong Wang @ 2016-01-02 0:34 UTC (permalink / raw) To: netdev-u79uwXL29TY76Z2rM5mHXA Cc: dvyukov-hpIqsD4AKlfQT0dZR+AlfA, linux-wireless-u79uwXL29TY76Z2rM5mHXA, Cong Wang, Lauro Ramos Venancio, Aloisio Almeida Jr, Samuel Ortiz 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_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c index 3621a90..5d94055 100644 --- a/net/nfc/llcp_commands.c +++ b/net/nfc/llcp_commands.c @@ -729,7 +729,7 @@ int nfc_llcp_send_ui_frame(struct nfc_llcp_sock *sock, u8 ssap, u8 dsap, if (local == NULL) return -ENODEV; - msg_data = kzalloc(len, GFP_KERNEL); + msg_data = kzalloc(len, GFP_USER | __GFP_NOWARN); if (msg_data == NULL) return -ENOMEM; -- 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] 4+ messages in thread
* [Patch net] nfc: check sock state in llcp_sock_getname() 2016-01-02 0:34 [Patch net] nfc: use GFP_USER for user-controlled kmalloc Cong Wang @ 2016-01-02 0:34 ` Cong Wang [not found] ` <1451694857-21873-2-git-send-email-xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Cong Wang @ 2016-01-02 0:34 UTC (permalink / raw) To: netdev Cc: dvyukov, linux-wireless, 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. We should just check if sk->sk_state is still closed since both connect() and bind() will update this state at the end. 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index ecf0a01..5a91997 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -500,7 +500,7 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr, struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk); DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, llcp_addr, uaddr); - if (llcp_sock == NULL || llcp_sock->dev == NULL) + if (llcp_sock == NULL || sk->sk_state == LLCP_CLOSED) return -EBADFD; pr_debug("%p %d %d %d\n", sk, llcp_sock->target_idx, -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <1451694857-21873-2-git-send-email-xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [Patch net] nfc: check sock state in llcp_sock_getname() [not found] ` <1451694857-21873-2-git-send-email-xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2016-01-02 8:03 ` Dmitry Vyukov [not found] ` <CACT4Y+Y6YCYA_v=--spYpPDYj3Jo0cXcntFRe8XzYS3NJFUwqQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Dmitry Vyukov @ 2016-01-02 8:03 UTC (permalink / raw) To: Cong Wang Cc: netdev, linux-wireless-u79uwXL29TY76Z2rM5mHXA, Lauro Ramos Venancio, Aloisio Almeida Jr, Samuel Ortiz On Sat, Jan 2, 2016 at 1:34 AM, Cong Wang <xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > > We should just check if sk->sk_state is still closed since > both connect() and bind() will update this state at the end. Hi Cong, This is still racy. If you want to play lock-free then you also need proper memory barriers. Stores to sk_state need to be smp_store_release, while the load needs to be smp_load_acquire. Otherwise getname still can see partially initialized socket. > 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 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c > index ecf0a01..5a91997 100644 > --- a/net/nfc/llcp_sock.c > +++ b/net/nfc/llcp_sock.c > @@ -500,7 +500,7 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr, > struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk); > DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, llcp_addr, uaddr); > > - if (llcp_sock == NULL || llcp_sock->dev == NULL) > + if (llcp_sock == NULL || sk->sk_state == LLCP_CLOSED) > return -EBADFD; > > pr_debug("%p %d %d %d\n", sk, llcp_sock->target_idx, > -- > 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 [flat|nested] 4+ messages in thread
[parent not found: <CACT4Y+Y6YCYA_v=--spYpPDYj3Jo0cXcntFRe8XzYS3NJFUwqQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [Patch net] nfc: check sock state in llcp_sock_getname() [not found] ` <CACT4Y+Y6YCYA_v=--spYpPDYj3Jo0cXcntFRe8XzYS3NJFUwqQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2016-01-03 22:36 ` Cong Wang 0 siblings, 0 replies; 4+ messages in thread From: Cong Wang @ 2016-01-03 22:36 UTC (permalink / raw) To: Dmitry Vyukov Cc: netdev, linux-wireless-u79uwXL29TY76Z2rM5mHXA, Lauro Ramos Venancio, Aloisio Almeida Jr, Samuel Ortiz On Sat, Jan 2, 2016 at 12:03 AM, Dmitry Vyukov <dvyukov-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> wrote: > On Sat, Jan 2, 2016 at 1:34 AM, Cong Wang <xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. >> >> We should just check if sk->sk_state is still closed since >> both connect() and bind() will update this state at the end. > > Hi Cong, > > This is still racy. If you want to play lock-free then you also need > proper memory barriers. Stores to sk_state need to be > smp_store_release, while the load needs to be smp_load_acquire. > Otherwise getname still can see partially initialized socket. > Right... Or just lock sock perhaps. I will update my patch. Thanks! -- 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 [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-03 22:36 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-01-02 0:34 [Patch net] nfc: use GFP_USER for user-controlled kmalloc Cong Wang 2016-01-02 0:34 ` [Patch net] nfc: check sock state in llcp_sock_getname() Cong Wang [not found] ` <1451694857-21873-2-git-send-email-xiyou.wangcong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2016-01-02 8:03 ` Dmitry Vyukov [not found] ` <CACT4Y+Y6YCYA_v=--spYpPDYj3Jo0cXcntFRe8XzYS3NJFUwqQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2016-01-03 22:36 ` Cong Wang
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).