Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864335rwb; Fri, 19 Aug 2022 10:39:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4D6g3P73GZY1er9BwwMBjV34CwsCOgL9gxtEwMcSKRK1Q/DdKQCSqibMMWfV2IZc4H83Xd X-Received: by 2002:a17:90b:238b:b0:1fa:d833:30dd with SMTP id mr11-20020a17090b238b00b001fad83330ddmr7092367pjb.147.1660930760961; Fri, 19 Aug 2022 10:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930760; cv=none; d=google.com; s=arc-20160816; b=wij1R5zZub1zJOYlELkicR10Yl0OMUrZ8BowFN1ex9ct2HvCZgvNLmCP3c228PhKni JiwuLcLk1/ffOAm5vmkXcPGR61jPEhoNRBJeRQv+iDEWwBA8/RMA16KhYIsAHTlXTqFp wYyjkX3a+aDcbF/U9pRX/6qXw4USWkBBcNtEosl3reQnx05BmJBxc5bdyONtcBZV7ONy tZ2/9nrFD6uattwcX6Gz9fq6PdX5M04VWO4jCoQYKG1aUa9bcoRALeBIt2o/LCJbvpXv vxS5MbXI8bQ7jye7itcRY+iahhqzV/8Ymrp03qo3uWAwY8Q99pFRYHu7rgtBCPL/yx/k 7slA== 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=0E7L1btA7bxiH2NmQMdEape/Mkeui4WRF9/d9/r+3Us=; b=ulIzNGSCvU2h5LW5CIFc3GlPuOweJFkNUHnxa9Np7EWMEx5cwV+WAzbz5w0Pt7ggDc RA0XcJLcIt+mrnB9WovXheWoaD7HOEgTmHadlxGSbC0+fzJYCKj9R1XXV1CqDL6Po7pz JxlLFlq0cg7Dax/PK5ICVARzoO5uOIx+hQF0KWmnHUlbOEXdgw89/40KYzldXDroZMZB Av1+5QqPsqeMiuIyetbC0LH11LFXIY1+J+nqXkL7YE+WrZA7gknYeyq5Dl5bYw7PDdA3 F40qFCeadQwTEQMHZDBHTFe22XiGWXbUWaF9SW1ZYmKCAwS9n6jKbugMNVF8j7EGrAUp xXCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GOHs3B9P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ix9-20020a170902f80900b0016f975be2f2si4204365plb.545.2022.08.19.10.39.10; Fri, 19 Aug 2022 10:39:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GOHs3B9P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1352054AbiHSQTD (ORCPT + 99 others); Fri, 19 Aug 2022 12:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352059AbiHSQPe (ORCPT ); Fri, 19 Aug 2022 12:15:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2702B67141; Fri, 19 Aug 2022 08:58:32 -0700 (PDT) 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 A1AAF6175A; Fri, 19 Aug 2022 15:58:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90267C433D7; Fri, 19 Aug 2022 15:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924711; bh=Da8cBBxBX4IhDdWFQDWVx1kklTczDRwaRgYukRzqfeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GOHs3B9Pt7fVrKDoZEQc79ivsShWBBXPbgOkS0dZRoHxDMruO5aoFcoe6dDodLAwh bKjSAZrU2qPplAxpmWvk8W2/Ssnzlq3WS9RWLEvmclCj+6I/9dy/Bz6QJ/QXe/yOD1 zz3ZDDVGfan666nGtxG/IR1IR1vGbjyl1k78Y6Lo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 258/545] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() Date: Fri, 19 Aug 2022 17:40:28 +0200 Message-Id: <20220819153840.900835053@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit fdb5fd7f736ec7ae9fb36d2842ea6d9ebc4e7269 ] inet_request_bound_dev_if() reads sk->sk_bound_dev_if twice while listener socket is not locked. Another cpu could change this field under us. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/inet_sock.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 3c039d4b0e48..886ed0950b7f 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -117,14 +117,15 @@ static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb) static inline int inet_request_bound_dev_if(const struct sock *sk, struct sk_buff *skb) { + int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); #ifdef CONFIG_NET_L3_MASTER_DEV struct net *net = sock_net(sk); - if (!sk->sk_bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) + if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) return l3mdev_master_ifindex_by_index(net, skb->skb_iif); #endif - return sk->sk_bound_dev_if; + return bound_dev_if; } static inline int inet_sk_bound_l3mdev(const struct sock *sk) -- 2.35.1