From: Paolo Abeni <pabeni@redhat.com>
To: Cong Wang <xiyou.wangcong@gmail.com>, netdev@vger.kernel.org
Cc: edumazet@google.com, Cong Wang <cong.wang@bytedance.com>,
syzbot+278279efdd2730dd14bf@syzkaller.appspotmail.com,
shaozhengchao <shaozhengchao@huawei.com>,
Tom Herbert <tom@herbertland.com>
Subject: Re: [Patch net v2] kcm: close race conditions on sk_receive_queue
Date: Tue, 08 Nov 2022 10:13:23 +0100 [thread overview]
Message-ID: <9ffe152671d4620eb1bfd443699c3143db377ca3.camel@redhat.com> (raw)
In-Reply-To: <20221103184620.359451-1-xiyou.wangcong@gmail.com>
Hello,
On Thu, 2022-11-03 at 11:46 -0700, Cong Wang wrote:
> @@ -1085,53 +1085,17 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
> return err;
> }
>
> -static struct sk_buff *kcm_wait_data(struct sock *sk, int flags,
> - long timeo, int *err)
> -{
> - struct sk_buff *skb;
> -
> - while (!(skb = skb_peek(&sk->sk_receive_queue))) {
> - if (sk->sk_err) {
> - *err = sock_error(sk);
> - return NULL;
> - }
> -
> - if (sock_flag(sk, SOCK_DONE))
> - return NULL;
It looks like skb_recv_datagram() ignores the SOCK_DONE flag, so this
change could potentially miss some wait_data end coditions. On the flip
side I don't see any place where the SOCK_DONE flag is set for the kcm
socket, so this should be safe, but could you please document this in
the commit message?
[...]
> @@ -1187,11 +1147,7 @@ static ssize_t kcm_splice_read(struct socket *sock, loff_t *ppos,
>
> /* Only support splice for SOCKSEQPACKET */
>
> - timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
> -
> - lock_sock(sk);
> -
> - skb = kcm_wait_data(sk, flags, timeo, &err);
> + skb = skb_recv_datagram(sk, flags, &err);
> if (!skb)
> goto err_out;
>
> @@ -1219,13 +1175,11 @@ static ssize_t kcm_splice_read(struct socket *sock, loff_t *ppos,
> * finish reading the message.
> */
>
> - release_sock(sk);
> -
> + skb_free_datagram(sk, skb);
> return copied;
>
> err_out:
> - release_sock(sk);
> -
> + skb_free_datagram(sk, skb);
We can reach here with skb == NULL and skb_free_datagram() ->
__kfree_skb() -> skb_release_all() does not deal correctly with NULL
skb, you need to check for skb explicitly here (or rearrange the error
paths in a suitable way).
Thanks!
Paolo
next prev parent reply other threads:[~2022-11-08 9:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 18:46 [Patch net v2] kcm: close race conditions on sk_receive_queue Cong Wang
2022-11-08 9:13 ` Paolo Abeni [this message]
2022-11-13 21:29 ` Cong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9ffe152671d4620eb1bfd443699c3143db377ca3.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=cong.wang@bytedance.com \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--cc=shaozhengchao@huawei.com \
--cc=syzbot+278279efdd2730dd14bf@syzkaller.appspotmail.com \
--cc=tom@herbertland.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox