Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3920342ybh; Tue, 17 Mar 2020 08:56:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuCcdIHIohUuCiOZLALq9lJjwTxl1avJ121YVGz3kF5nnIvm47H8IpNah5yNlF4HFrlEYrh X-Received: by 2002:aca:bd46:: with SMTP id n67mr951oif.120.1584460572092; Tue, 17 Mar 2020 08:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584460572; cv=none; d=google.com; s=arc-20160816; b=gcCrfAstQmj/ou7qolY7Ax13fwkOVOxMihFwQK7VnT8YRPvz4SB5ftuXJH1uteUdJ6 nDJTRhwQf9TtKW6vV8iwaNRcf/c3ieEJE7LnU4ntoXA2faGm1afY8287g8cWYwvXF0QE RzvPimpVU2Oaqd83rhcFpT3SDGZxaerqOirkrMNrSHzFLP77fK+6SQWR0d0JADgEI9vM j+GVmJziTPDoly6L9ULV7vOUY2CDdNkUITC5KwM7lFkgmY/jH+U3FKMUNZ4BJhGiBwZo sH8qb64Kayd81K+xIP55uBs0+8gs08592I9quLBDX9NDlPkvRF8eh0rYZFDVLDyMgeMI yHAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=rIOYXa4n3W4fvDIFexK8Xd1iAbQHd2/NWX4UF2y8JPU=; b=U5ZCqVY2cKbNw/779TZYbHdGR1Om1s2bLvuKyUnI2P8qMba8kmrISj26X34MqGBebS EztixsJegGckHtejbPf51N5eOGAFWcm6LyuRVkhUgBuKPN83zUqQieJtFUYbKuqyzu3e vMaDrpTtY+amiog6mNYx9XngCNfTlH3PNJitfk1q3BG6pzOZms2XHjCc1zgY58Mo3R/n Dx/CaR/3lc5HxfliNnoOS7WWvJjImWvx7qIGgSnGwPp016bUb3cp8twGiBeZh8t36Id2 6HF2j1PAzi93LtED71XWtkidXEhQaeGnTWpDUm4oc7hWAEUw88FnqAbnDmoiW7oGrmOD YPlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=irfrBskV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18si1628435oie.189.2020.03.17.08.55.58; Tue, 17 Mar 2020 08:56:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=irfrBskV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbgCQPzo (ORCPT + 99 others); Tue, 17 Mar 2020 11:55:44 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:55541 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbgCQPzo (ORCPT ); Tue, 17 Mar 2020 11:55:44 -0400 Received: by mail-pj1-f65.google.com with SMTP id mj6so10173736pjb.5; Tue, 17 Mar 2020 08:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rIOYXa4n3W4fvDIFexK8Xd1iAbQHd2/NWX4UF2y8JPU=; b=irfrBskVIzOYnt/8r4tZQkRb68wX1xdH3cibG7ArPih3W4C8DDXVzgNH550GQ96uAr jqoYAlgRrigTEqn3/aSlfNxHsiqOPz8uSpuxx032eJ1yTZFg7zVtabnFhEjkdfuXwHQC ZptWEZfY/eBxexy70Z6S05vR1GuZjwB8UEArvF4djW+XTlobg7LpVrFmKkUJ5IAuD9w4 ShHyFljj8mHxonbV1k6VGzmLVXAQVDsiD3Fv5iYzEM0Cp6vv1kPRKTZQ+q+ejfWOhSL3 l6ZOb71iiAsJcf3s/dNYOvvI/VIngpu4fwhYmDyFnaZorpKvJ5cNbswj6fBnOkCZh8CM NyFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rIOYXa4n3W4fvDIFexK8Xd1iAbQHd2/NWX4UF2y8JPU=; b=kzf0S5W4ROoCDhdY7wzm8EHP5t0ArTNqeqou1uVvNVr/LAfD8jEnD9vX84rNHyY9Ed MN9Ba83VDW3FqgNf03+Hj77YKLvQbAs5V3mYQIkYQl6qd64gN3kqEutHEeE9mNtdQiLD x1Bde86f8brDkn27UPfxoJQskK6hQrlI+Pedy/SJH7iqW6Vlv/tRxP2UMMgHScGuPile wTP5tU0f/AJPAW7nsorPWJfsLvt5ygZ2sNm/hamD7cHsSl0PzESxJOKmUfREHuXuqch2 /gTIWVHBVcB6lqWHsFmHs/25TJhszxEg8hPbOq6VciyuxnMW74aTKwu7m8be50clQXrI ygSw== X-Gm-Message-State: ANhLgQ18q5Mwu8Bm105BZuGWJ1AcQBDku7XdXDn7nkRipi3DvKtGoFfG UkczOs8dvp3lqyMel87dDPQ= X-Received: by 2002:a17:902:d712:: with SMTP id w18mr5146760ply.238.1584460542597; Tue, 17 Mar 2020 08:55:42 -0700 (PDT) Received: from localhost ([161.117.239.120]) by smtp.gmail.com with ESMTPSA id s19sm3665027pfh.218.2020.03.17.08.55.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Mar 2020 08:55:41 -0700 (PDT) From: Qiujun Huang To: marcelo.leitner@gmail.com, davem@davemloft.net Cc: vyasevich@gmail.com, nhorman@tuxdriver.com, kuba@kernel.org, linux-sctp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, anenbupt@gmail.com, Qiujun Huang Subject: [PATCH v2] sctp: fix refcount bug in sctp_wfree Date: Tue, 17 Mar 2020 23:55:36 +0800 Message-Id: <20200317155536.10227-1-hqjagain@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do accounting for skb's real sk. In some case skb->sk != asoc->base.sk: migrate routing sctp_check_transmitted routing ------------ --------------- lock_sock_nested(); mv the transmitted skb to the it's local tlist 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 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 --- 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