Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1755190pxb; Wed, 9 Feb 2022 03:56:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWAReilk5AGEGI3pUL9/HuOn2ApRCZG6m03Wg6vcejWtGrjiP9Dwg/YrgbN6yIHIsGN4+W X-Received: by 2002:a17:90a:d78e:: with SMTP id z14mr2983893pju.68.1644407783975; Wed, 09 Feb 2022 03:56:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644407783; cv=none; d=google.com; s=arc-20160816; b=aQZHH9dcle0fNXJn/BexN22lQCfkX7o3Un+gc4cyaBXwoMoSfaZncFSVTi/NjIxI4T uHm8GHswIqAP+3PtQyLZw9RQdLSH9RZi25wD6cx7T8WGR3LxSz8rAPA2ypYzcxsQMm71 2SfJjSp9wqqe4Qp+70o4i9EC9yBL9AK6IVJvG1xknXQ5BXUk2rpmrypmaosKRw1l8ZoX U/jqrJjfNVPPM8hSIqHVO4OMO7+cMAB7TOPMhWQ2admc2XE9KUrFI74efrMMolKXLn/E jnUP+SPUKrZn7MwbwyNyE7f0vSQoHefyhsuJ93vifEB6A8FCQ+MH59UQ5j+UcmlnECR+ mAZg== 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=alpRUtOm/FSA2DqmbwqfRFNXMIr+pW/okPIWzzWsr2I=; b=Pm8Z3M42QX09p0VPVmwRulLmd0zMe+gRgTXfbzs7h7KR7clULc2fEagxgudHSOS3Ok F2RZ3+TAVCcDjQfHw97nbD8BFoWQPzIYGcMWBCrjrSuVixJLaEwglx1QXhm3mH03LFWI ovva79LAfyhKk3vdPMZqPa0YntbTPh921WP3x6DfPJyV6uVoBmuAFKVHLdjIRzStBaqZ 8pGBssa8lIA9onGTgV6RwvHWUlVO+Yik2zO0PVe2KAG9KZhcvvtVt4dREWSMsJBntDlM ND8YVAIINMNnhydzAymctlNmif48WcxDvX8h76bTKDfphYjd8cYkqOZ7AvkIgdZEyQxZ PlOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IzmuKsiQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c14si5745970pfl.136.2022.02.09.03.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:56:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IzmuKsiQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52AB3E0EB0B6; Wed, 9 Feb 2022 02:02:18 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380543AbiBGLQx (ORCPT + 99 others); Mon, 7 Feb 2022 06:16:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379698AbiBGLQP (ORCPT ); Mon, 7 Feb 2022 06:16:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D926C043189; Mon, 7 Feb 2022 03:16:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7F51B6113B; Mon, 7 Feb 2022 11:16:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F1B3C004E1; Mon, 7 Feb 2022 11:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232572; bh=F9nM7RC2KedaKUX+hil3fXIdjk9e2x621P2GLnez9Eo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IzmuKsiQzbvB537vUoUqWs6PuSxNoujvRVzqKljLDE1wM2PhmaWDktfiDDj1NOSDG W9LUkgz0EvGwlHE5VZodToB32sEKqhTnX8eSvq9MusdqXAJiJ8srv2utFoNkMlm9zI JYVNmRo+Nf/xFhnctehPn6rbzr/DRHuUCWlrRElw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Jiri Pirko , Jakub Kicinski Subject: [PATCH 4.19 52/86] rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink() Date: Mon, 7 Feb 2022 12:06:15 +0100 Message-Id: <20220207103759.263872926@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit c6f6f2444bdbe0079e41914a35081530d0409963 upstream. While looking at one unrelated syzbot bug, I found the replay logic in __rtnl_newlink() to potentially trigger use-after-free. It is better to clear master_dev and m_ops inside the loop, in case we have to replay it. Fixes: ba7d49b1f0f8 ("rtnetlink: provide api for getting and setting slave info") Signed-off-by: Eric Dumazet Cc: Jiri Pirko Link: https://lore.kernel.org/r/20220201012106.216495-1-eric.dumazet@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/rtnetlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2942,9 +2942,9 @@ static int rtnl_newlink(struct sk_buff * { struct net *net = sock_net(skb->sk); const struct rtnl_link_ops *ops; - const struct rtnl_link_ops *m_ops = NULL; + const struct rtnl_link_ops *m_ops; struct net_device *dev; - struct net_device *master_dev = NULL; + struct net_device *master_dev; struct ifinfomsg *ifm; char kind[MODULE_NAME_LEN]; char ifname[IFNAMSIZ]; @@ -2979,6 +2979,8 @@ replay: dev = NULL; } + master_dev = NULL; + m_ops = NULL; if (dev) { master_dev = netdev_master_upper_dev_get(dev); if (master_dev)