Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2498374imm; Mon, 24 Sep 2018 05:30:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdadSogkBks9De4RHOlV/judwH7NpZmh4MQNfxh4Awt988hsLbwAqUbZf3yX3mQCFu/LJlrj X-Received: by 2002:a62:858c:: with SMTP id m12-v6mr10281087pfk.173.1537792215559; Mon, 24 Sep 2018 05:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792215; cv=none; d=google.com; s=arc-20160816; b=aUVhffFDS6eoL7oF1O2I1zaL/OObFrp0e/APiiQIvTHHdm2gakD6z4MLMhR64U5GEe utuoy+lYRvZ2wAxXXVHx6CsqphI1d/gLjmu3Q9OhAN2DkxfJhTcCrhfbHUSurkv8xBPm p7z3LC+1vB/UPQill+3lbroFwLxrieSRAoS09uXh+7+AA2ehd75DxwKGoZfBd0uXIxCh jkOcW0/v9UkNx8ZYkOzu9IXv/TEgcIW85CUZkTIwdscnZZIbT2hqn+WTyTqRfWxFLA33 kIbAe2d+XOaUWH4vz/SSsRDRdm5Q+QVrF+FpZpbTyBnldvpDfnQismq1sqZU7XdzoB6O 4JBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=OPYNwIsdVKLGnOEDX0/+v7gmoVVuq8MLRdE4U3+4HuU=; b=Y0f7RSLT6q8V/nBhUXX+XoWy4T9DXlOsEY2a86CkhS6rAh2yqJlRShUHBe9y/LLI8F vvmRK9K/lckWM6zOBttEROQ5kbGqOOUwWhV7BIrDqQv9LcFfA3nMYe5M+t2KxZXqoqX9 kasitO6b6XuVmLyBYAA2Z+r3e3ifGDPkueSTa9OuXKcRuz5tSo9uBWNY7dM1AyvDPQzD H0OQ7wp3YdidZ/FPWn7c4lRcEuRDVUna24+AEH/Fv0YKc+ktXPNOJC8XoBhkCaZo4BHC C4xLdSIA9m9DouPu5jTHPioyzetxx3arhEHL7lMV1isiFFRp2r4zx1jx2oFoa0/uaKRn IJpA== 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 s3-v6si37553761plb.270.2018.09.24.05.29.59; Mon, 24 Sep 2018 05:30:15 -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 S2387631AbeIXSau (ORCPT + 99 others); Mon, 24 Sep 2018 14:30:50 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57530 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732275AbeIXSat (ORCPT ); Mon, 24 Sep 2018 14:30:49 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4125D1094; Mon, 24 Sep 2018 12:28:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+93a5839deb355537440f@syzkaller.appspotmail.com, Sowmini Varadhan , Santosh Shilimkar , rds-devel@oss.oracle.com, Cong Wang , Santosh Shilimkar , "David S. Miller" Subject: [PATCH 4.18 004/235] rds: fix two RCU related problems Date: Mon, 24 Sep 2018 13:49:50 +0200 Message-Id: <20180924113104.696412478@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit cc4dfb7f70a344f24c1c71e298deea0771dadcb2 ] When a rds sock is bound, it is inserted into the bind_hash_table which is protected by RCU. But when releasing rds sock, after it is removed from this hash table, it is freed immediately without respecting RCU grace period. This could cause some use-after-free as reported by syzbot. Mark the rds sock with SOCK_RCU_FREE before inserting it into the bind_hash_table, so that it would be always freed after a RCU grace period. The other problem is in rds_find_bound(), the rds sock could be freed in between rhashtable_lookup_fast() and rds_sock_addref(), so we need to extend RCU read lock protection in rds_find_bound() to close this race condition. Reported-and-tested-by: syzbot+8967084bcac563795dc6@syzkaller.appspotmail.com Reported-by: syzbot+93a5839deb355537440f@syzkaller.appspotmail.com Cc: Sowmini Varadhan Cc: Santosh Shilimkar Cc: rds-devel@oss.oracle.com Signed-off-by: Cong Wang Acked-by: Santosh Shilimkar Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/rds/bind.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/net/rds/bind.c +++ b/net/rds/bind.c @@ -60,11 +60,13 @@ struct rds_sock *rds_find_bound(__be32 a u64 key = ((u64)addr << 32) | port; struct rds_sock *rs; - rs = rhashtable_lookup_fast(&bind_hash_table, &key, ht_parms); + rcu_read_lock(); + rs = rhashtable_lookup(&bind_hash_table, &key, ht_parms); if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD)) rds_sock_addref(rs); else rs = NULL; + rcu_read_unlock(); rdsdebug("returning rs %p for %pI4:%u\n", rs, &addr, ntohs(port)); @@ -157,6 +159,7 @@ int rds_bind(struct socket *sock, struct goto out; } + sock_set_flag(sk, SOCK_RCU_FREE); ret = rds_add_bound(rs, sin->sin_addr.s_addr, &sin->sin_port); if (ret) goto out;