Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1576028pxb; Tue, 8 Feb 2022 22:51:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJynEp0X+Yz1bB6I9GdknmW5JJ0hvhLHZm7GT84B2PrwZglYYspi58AoYaRv/qNaU94iVLlB X-Received: by 2002:a63:84c3:: with SMTP id k186mr757932pgd.553.1644389486626; Tue, 08 Feb 2022 22:51:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644389486; cv=none; d=google.com; s=arc-20160816; b=DfXt3QphwGBJtX9382K6cscmG1djdVVHEjIYVHQI7MLPeRuF5O9S5mH389KDuvgb6H wL1RdwwMXp6jFHNwmQx5zJLpE5eho8mf+ZSQKrf6zEcno91pc5pTY9kRliBSo0ZMTjCh a71HUG76i8B7Q8pr4trtM3RCP3qPgZpr366TAskkjmDJef4cdWpsjdir2s3zvrzbaeC/ H4RtiSOHwRrgFaSTlsIaqdKp8p30hrPXiSdlVdQAMrQdeafEuwQ5tmnixbY71SC763bY ce+m7cTs9Ac843EHEmaLK3DfkHqIdIlYqGE6K8nJkx02bor8YLtGddy/YQfZDTz8Hmch BlgA== 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=LQgdTvpVEygMGfbaGWuDFvezDI58hectNCWP2DheSXs=; b=Iw+tyuX0tMcKVDP2MDiy6HP78bISRbM2Wrr0iG7OlY6VTQ2uSTmBImXDqXNIMGX2wG nYX1Us5sdpnBXz8IpKduyenPcToFUjCoSkGeTNhpjDYC6mMDYVbi4cSXTdpa1+1cVTgh ijbb9Rx+bnUaQpUBu2Td+vtj/jfClTI9AKQMIWunhZQHLD+BJDrrdQwnhcdwbqESsXK6 LPQ4Dg1gS1MRtULBfP4e5RLobq4w9e9iNpZjgSlD3AIzyalFIA0hUC1iXNbGoDOxbM4r myffGCh2nVR4cOnsNfKO9H/f2DOCvjb7+3IxSPWCDd5Ez4KpaIBu1qhDk+CoewRDZ13v x9Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m43e5Htf; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id h1si14946692pgq.150.2022.02.08.22.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 22:51:26 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m43e5Htf; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 59E05C0DE7D8; Tue, 8 Feb 2022 22:23:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358353AbiBDJaQ (ORCPT + 99 others); Fri, 4 Feb 2022 04:30:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357775AbiBDJ22 (ORCPT ); Fri, 4 Feb 2022 04:28:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B636DC061776; Fri, 4 Feb 2022 01:27:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 80E19B836EE; Fri, 4 Feb 2022 09:27:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A21D1C004E1; Fri, 4 Feb 2022 09:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643966825; bh=Ai2pTBuMpi+ZpmwAJGWmVGypw5mKsno03Np5MzaPBcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m43e5HtfpO5oEd68qu9XGW4B1r6BCor85Gtz5Ly+pSAYg98khbr8Ez97jQ0otfHnB UG8PQevj+q4e46MscLpDoH1nsL+UpKSRZrJ7MPFjx+vbcvAdmoTfzpL6nvWQ7VCNFH frZ6SmYQauchIYfXt3TfEMwZXJf1fQ12HOVkT4NI= 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 5.16 36/43] rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink() Date: Fri, 4 Feb 2022 10:22:43 +0100 Message-Id: <20220204091918.340196380@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220204091917.166033635@linuxfoundation.org> References: <20220204091917.166033635@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 X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 @@ -3254,8 +3254,8 @@ static int __rtnl_newlink(struct sk_buff struct nlattr *slave_attr[RTNL_SLAVE_MAX_TYPE + 1]; unsigned char name_assign_type = NET_NAME_USER; struct nlattr *linkinfo[IFLA_INFO_MAX + 1]; - const struct rtnl_link_ops *m_ops = NULL; - struct net_device *master_dev = NULL; + const struct rtnl_link_ops *m_ops; + struct net_device *master_dev; struct net *net = sock_net(skb->sk); const struct rtnl_link_ops *ops; struct nlattr *tb[IFLA_MAX + 1]; @@ -3293,6 +3293,8 @@ replay: else dev = NULL; + master_dev = NULL; + m_ops = NULL; if (dev) { master_dev = netdev_master_upper_dev_get(dev); if (master_dev)