lkml.org 
[lkml]   [2020]   [Mar]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] sctp: fix refcount bug in sctp_wfree
Hi,

On Tue, Mar 17, 2020 at 11:55:36PM +0800, Qiujun Huang wrote:
> Do accounting for skb's real sk.
> In some case skb->sk != asoc->base.sk:
>
> migrate routing sctp_check_transmitted routing
> ------------ ---------------
sctp_close();
lock_sock(sk2);
sctp_primitive_ABORT();
sctp_do_sm();
sctp_cmd_interpreter();
sctp_cmd_process_sack();
sctp_outq_sack();
sctp_check_transmitted();

lock_sock(sk1);
sctp_getsockopt_peeloff();
sctp_do_peeloff();
sctp_sock_migrate();
> lock_sock_nested(sk2);
> mv the transmitted skb to
> the it's local tlist


How can sctp_do_sm() be called in the 2nd column so that it bypasses
the locks in the left column, allowing this mv to happen?

>
> sctp_for_each_tx_datachunk(
> sctp_clear_owner_w);
> sctp_assoc_migrate();
> sctp_for_each_tx_datachunk(
> sctp_set_owner_w);
>
> put the skb back to the
> assoc lists
> ----------------------------------------------------
>
> The skbs which held bysctp_check_transmitted were not changed
> to newsk. They were not dealt with by sctp_for_each_tx_datachunk
> (sctp_clear_owner_w/sctp_set_owner_w).

It would make sense but I'm missing one step earlier, I'm not seeing
how the move to local list is allowed/possible in there. It really
shouldn't be possible.

>
> It looks only trouble here so handling it in sctp_wfree is enough.
>
> Reported-and-tested-by: syzbot+cea71eec5d6de256d54d@syzkaller.appspotmail.com
> Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
> ---
> net/sctp/socket.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 1b56fc440606..5f5c28b30e25 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -9080,7 +9080,7 @@ static void sctp_wfree(struct sk_buff *skb)
> {
> struct sctp_chunk *chunk = skb_shinfo(skb)->destructor_arg;
> struct sctp_association *asoc = chunk->asoc;
> - struct sock *sk = asoc->base.sk;
> + struct sock *sk = skb->sk;
>
> sk_mem_uncharge(sk, skb->truesize);
> sk->sk_wmem_queued -= skb->truesize + sizeof(struct sctp_chunk);
> @@ -9109,7 +9109,7 @@ static void sctp_wfree(struct sk_buff *skb)
> }
>
> sock_wfree(skb);
> - sctp_wake_up_waiters(sk, asoc);
> + sctp_wake_up_waiters(asoc->base.sk, asoc);
>
> sctp_association_put(asoc);
> }
> --
> 2.17.1
>

\
 
 \ /
  Last update: 2020-03-17 18:32    [W:0.042 / U:0.300 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site