Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2759840ybi; Sun, 9 Jun 2019 20:26:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfdzIvRTVYdDfBWoKkN1fxWTKaL8CqDyjISSwsLND3d1sM4reSXo49s7nidk/tGiKJkr+Z X-Received: by 2002:a17:90a:1c17:: with SMTP id s23mr10489968pjs.108.1560137169349; Sun, 09 Jun 2019 20:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560137169; cv=none; d=google.com; s=arc-20160816; b=JwUxdwsEiF3qPeFvmhiQPVGz8/e43hGqTuSJXsfubXP4yZAqI+XZBhY3H0OhVqESlB L1DkcJRssm/TDQ3VuNXVz8DfHHwx0qKqIAem+9DSGR3i7FCPpSNWkt/+vY/Q8TNTsyZV qBwjrQ0+9BC06fs98vdya28yNrEJ0AfrG9wlGKKgXWJRAqPZIhbFyFsGGujSx86IlThe jRFPoDxsMGn8quEPgMiRpsq57xb9+h2rPa1SC0R3N+eeAq3Xo/aanjWIKqAJ5kIIJHNg 7WEX9pGttpiLd5O3C2H70ADadXWOeuBp8/gwykRnB5DPN+eCjESWUvrBulusYshSsd99 nQRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=7dZj9P1m0uyAuXiFX5lhnE2EnMpcgIGt/eibcpYi4uI=; b=cJ3sA+y/iXmiO6xdjEQP7bo4c0f2/a8BNIw8kWFIMoHdWAhGYlDUysCKnLCmUAhr2A gZJdLxb9wd8f4fh24dUtv2MKW1XB2BpNFNALB0++TbZlslbgP/iqG63a5SFOZsONgpDx Cm/NubdSdK7nDXjsUWGFwkq+fCPNhoeTVgXlfDKhrcffLHCNwTNZhgMapbUpf/blppoa obN73tR9uU/l/Q1Isn6RoA6e7C+cmvZk+ju6a9kue+BrnuzqormsGqQ8toRYg9sff8js FnCeEl4QU753dWJvP9+QfHe8gmdopy3Tv+WIUCY9k7DiGs4Wnni37i2LrGf0QAD255Ei xTnA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j38si8620287pgi.227.2019.06.09.20.25.54; Sun, 09 Jun 2019 20:26:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387565AbfFJDY0 (ORCPT + 99 others); Sun, 9 Jun 2019 23:24:26 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:16421 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387483AbfFJDYZ (ORCPT ); Sun, 9 Jun 2019 23:24:25 -0400 X-IronPort-AV: E=Sophos;i="5.63,572,1557158400"; d="scan'208";a="66690332" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Jun 2019 11:24:14 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 5D60E4CDD44A; Mon, 10 Jun 2019 11:24:11 +0800 (CST) Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 10 Jun 2019 11:24:15 +0800 From: Su Yanjun To: , , , CC: , , , Su Yanjun Subject: [PATCH] sctp: Add rcu lock to protect dst entry in sctp_transport_route Date: Mon, 10 Jun 2019 11:20:00 +0800 Message-ID: <1560136800-17961-1-git-send-email-suyj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.167.226.33] X-yoursite-MailScanner-ID: 5D60E4CDD44A.ADDBD X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suyj.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org syzbot found a crash in rt_cache_valid. Problem is that when more threads release dst in sctp_transport_route, the route cache can be freed. As follows, p1: sctp_transport_route dst_release get_dst p2: sctp_transport_route dst_release get_dst ... If enough threads calling dst_release will cause dst->refcnt==0 then rcu softirq will reclaim the dst entry,get_dst then use the freed memory. This patch adds rcu lock to protect the dst_entry here. Fixes: 6e91b578bf3f("sctp: re-use sctp_transport_pmtu in sctp_transport_route") Signed-off-by: Su Yanjun Reported-by: syzbot+a9e23ea2aa21044c2798@syzkaller.appspotmail.com --- net/sctp/transport.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/sctp/transport.c b/net/sctp/transport.c index ad158d3..5ad7e20 100644 --- a/net/sctp/transport.c +++ b/net/sctp/transport.c @@ -308,8 +308,13 @@ void sctp_transport_route(struct sctp_transport *transport, struct sctp_association *asoc = transport->asoc; struct sctp_af *af = transport->af_specific; + /* When dst entry is being released, route cache may be referred + * again. Add rcu lock here to protect dst entry. + */ + rcu_read_lock(); sctp_transport_dst_release(transport); af->get_dst(transport, saddr, &transport->fl, sctp_opt2sk(opt)); + rcu_read_unlock(); if (saddr) memcpy(&transport->saddr, saddr, sizeof(union sctp_addr)); -- 2.7.4