Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3422184pxf; Mon, 29 Mar 2021 01:36:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxShBf4uYt9TQjtmNi9sSqmNrpVR0pXYDFdx13AEGoUE+UN7SjoHnPUpoEBnUW9g7WJjxdY X-Received: by 2002:a17:906:7d82:: with SMTP id v2mr27645415ejo.524.1617006984925; Mon, 29 Mar 2021 01:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617006984; cv=none; d=google.com; s=arc-20160816; b=P1ylWB+OJnQB4Nnl3dVv5lusdexpYELcRunyrrSbXy4s/WM2GdZbP/0j7/8+20fkFr FPme4mUzPtfz2f8flt9RCUpCuYNYaVYfd7Id72FKfZQPgW5vtP9X18lX7fwQRN82N4gC mCh5/VgCrqBGj5uHa32HnaZcEyZW9G/6L2yTlxLgKFZbNb5RePSW2gra1EROBVED31eg 1XbKTIhSBERenBTvpFPWzcr0A/2lxviU/xCSNuaGXkP1GthHmJLOOHNrvxU+rcPmT239 PJuDMngeziNLAEFhpuCqRLGd++ZqliUYh3MpZSKDF+geFIlFLFNlEWBV57H3MfJGrBnk T+vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XVWAKTZjH0jj29KQXT2xJGOfpshwQUw+6DAetwaIBC0=; b=UXlMWWu7HWZvvrbtY9ZuapcN5oPW/A0pSTAFD9zQLcfpJiHM7TSwxssFCZDuZszH9v OoFaeE5KGpM0R2NaZnd96HKqvzul0shjFKm7sqAUMeCTfEsVQsIbif4gyjhUMdiktnlC oW4wOVtfFn4GBTJpRx4cF8awLIDtIjQ51asKwQva8jN+EuCwJ5hWAY/+W+35+vwIU0sd YjkpS4e/3BIbYxeYsq8MyrZ94kEVOc8180+xORUpoHDUKjRw80etMueCW+zYSIVMphuc UM4Rom8UL8cAKNTJKKpDM8ax/gJZ2uJmkwAKZOrX0Dz8MH1l+OH6BKN5Ufw8ZdevbDW/ hPRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pmpyUYbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si12167597edq.492.2021.03.29.01.35.50; Mon, 29 Mar 2021 01:36:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pmpyUYbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232267AbhC2Iet (ORCPT + 99 others); Mon, 29 Mar 2021 04:34:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:38286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbhC2IVY (ORCPT ); Mon, 29 Mar 2021 04:21:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4528561580; Mon, 29 Mar 2021 08:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006071; bh=b3VEMJT60IezzqEOtJU0IXAyPbI/zH0cbmJTP/1S5g4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pmpyUYbA0U8G6MH9H/5b+3mktcnr355+ffO6BhjUIH59Bk1jXWvgmhSS3mtfZMrcL 5rrWYj5HQikWq8k+a1214GaMxdtZLWRQW9HKWGB3b5scLEKoIeZ2p9mhkvlqGH3qWn 4WgS/uBHmakbZYcpKc7Vyr9yad+fp0Hnk7Kee85k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Wei Wang , David Ahern , Ido Schimmel , Petr Machata , Eric Dumazet , Ido Schimmel , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 100/221] ipv6: fix suspecious RCU usage warning Date: Mon, 29 Mar 2021 09:57:11 +0200 Message-Id: <20210329075632.538293477@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei Wang [ Upstream commit 28259bac7f1dde06d8ba324e222bbec9d4e92f2b ] Syzbot reported the suspecious RCU usage in nexthop_fib6_nh() when called from ipv6_route_seq_show(). The reason is ipv6_route_seq_start() calls rcu_read_lock_bh(), while nexthop_fib6_nh() calls rcu_dereference_rtnl(). The fix proposed is to add a variant of nexthop_fib6_nh() to use rcu_dereference_bh_rtnl() for ipv6_route_seq_show(). The reported trace is as follows: ./include/net/nexthop.h:416 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 2 locks held by syz-executor.0/17895: at: seq_read+0x71/0x12a0 fs/seq_file.c:169 at: seq_file_net include/linux/seq_file_net.h:19 [inline] at: ipv6_route_seq_start+0xaf/0x300 net/ipv6/ip6_fib.c:2616 stack backtrace: CPU: 1 PID: 17895 Comm: syz-executor.0 Not tainted 4.15.0-syzkaller #0 Call Trace: [] __dump_stack lib/dump_stack.c:17 [inline] [] dump_stack+0xd8/0x147 lib/dump_stack.c:53 [] lockdep_rcu_suspicious+0x153/0x15d kernel/locking/lockdep.c:5745 [] nexthop_fib6_nh include/net/nexthop.h:416 [inline] [] ipv6_route_native_seq_show net/ipv6/ip6_fib.c:2488 [inline] [] ipv6_route_seq_show+0x436/0x7a0 net/ipv6/ip6_fib.c:2673 [] seq_read+0xccf/0x12a0 fs/seq_file.c:276 [] proc_reg_read+0x10c/0x1d0 fs/proc/inode.c:231 [] do_loop_readv_writev fs/read_write.c:714 [inline] [] do_loop_readv_writev fs/read_write.c:701 [inline] [] do_iter_read+0x49e/0x660 fs/read_write.c:935 [] vfs_readv+0xfb/0x170 fs/read_write.c:997 [] kernel_readv fs/splice.c:361 [inline] [] default_file_splice_read+0x487/0x9c0 fs/splice.c:416 [] do_splice_to+0x129/0x190 fs/splice.c:879 [] splice_direct_to_actor+0x256/0x890 fs/splice.c:951 [] do_splice_direct+0x1dd/0x2b0 fs/splice.c:1060 [] do_sendfile+0x597/0xce0 fs/read_write.c:1459 [] SYSC_sendfile64 fs/read_write.c:1520 [inline] [] SyS_sendfile64+0x155/0x170 fs/read_write.c:1506 [] do_syscall_64+0x1ff/0x310 arch/x86/entry/common.c:305 [] entry_SYSCALL_64_after_hwframe+0x42/0xb7 Fixes: f88d8ea67fbdb ("ipv6: Plumb support for nexthop object in a fib6_info") Reported-by: syzbot Signed-off-by: Wei Wang Cc: David Ahern Cc: Ido Schimmel Cc: Petr Machata Cc: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/nexthop.h | 24 ++++++++++++++++++++++++ net/ipv6/ip6_fib.c | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 2fd76a9b6dc8..4c8c9fe9a3f0 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -362,6 +362,7 @@ static inline struct fib_nh *fib_info_nh(struct fib_info *fi, int nhsel) int fib6_check_nexthop(struct nexthop *nh, struct fib6_config *cfg, struct netlink_ext_ack *extack); +/* Caller should either hold rcu_read_lock(), or RTNL. */ static inline struct fib6_nh *nexthop_fib6_nh(struct nexthop *nh) { struct nh_info *nhi; @@ -382,6 +383,29 @@ static inline struct fib6_nh *nexthop_fib6_nh(struct nexthop *nh) return NULL; } +/* Variant of nexthop_fib6_nh(). + * Caller should either hold rcu_read_lock_bh(), or RTNL. + */ +static inline struct fib6_nh *nexthop_fib6_nh_bh(struct nexthop *nh) +{ + struct nh_info *nhi; + + if (nh->is_group) { + struct nh_group *nh_grp; + + nh_grp = rcu_dereference_bh_rtnl(nh->nh_grp); + nh = nexthop_mpath_select(nh_grp, 0); + if (!nh) + return NULL; + } + + nhi = rcu_dereference_bh_rtnl(nh->nh_info); + if (nhi->family == AF_INET6) + return &nhi->fib6_nh; + + return NULL; +} + static inline struct net_device *fib6_info_nh_dev(struct fib6_info *f6i) { struct fib6_nh *fib6_nh; diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index f43e27555725..1fb79dbde0cb 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -2485,7 +2485,7 @@ static int ipv6_route_native_seq_show(struct seq_file *seq, void *v) const struct net_device *dev; if (rt->nh) - fib6_nh = nexthop_fib6_nh(rt->nh); + fib6_nh = nexthop_fib6_nh_bh(rt->nh); seq_printf(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen); -- 2.30.1