Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp632557iog; Mon, 13 Jun 2022 09:32:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiQgL28sLkNtvZQ9Q2mAgfLq/jBQI+dl6YkDrgh6c4ettztHUvMjbgazn5gY6sd5wBaVSN X-Received: by 2002:a05:6a00:26cf:b0:4f6:fc52:7b6a with SMTP id p15-20020a056a0026cf00b004f6fc527b6amr140996pfw.39.1655137920192; Mon, 13 Jun 2022 09:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137920; cv=none; d=google.com; s=arc-20160816; b=n3+fdwxIhTwGUrsvyvQyXel9YAy2Vs9eaL17qz4lBzZgt3lBHIDhBsmgpajic7kNG1 gLDXaSVquBpGKSOVoGwUnHEF7E5t8zJnIEu17GvWgNCQ3WXyx3yanf7SIWuBTV/LN8hl CA1hcX/cLVNicPErrWH4DmiVYGiVTeJMkMXSnblBKOrG5X1WTCqLhuUUzNhTLl+4cKCy LEiU/4v2NyN9qs2XfBip3VExSe9ByqIQqya6RYDSNtBYjOVrMF4/cgqzGrCB+OwmKt5Z FXHhiUD2IcznDM5IvWdqHD0Urcwe9k+td2Vl/MZX4KTVzvTfDC1gPK2r9l9iYL6m3j3a +vWQ== 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=yaGgHQPaNpeBgZjPgLhi15AYeamFd2fVx0YXohxh7GM=; b=wdzfGY1GYeRHS+a81KBFixUhi9W/WTulRCrAaosXeFz2JFEk1aqBetjb9i0i+0OR3e fQmF9yhKXqUIAGCn7/cZip8ZpCC2w1PcmdBSOpAN2281VvYtGuqqbB5PHshWI/QCp228 25TyLK0F5fO4yGdVZ8Ws5YAyh45bRUGn/X/ALx+YTG4sgXr+vsy9ZYUvKMIiMvYLOxZu agypQJ3XwU7koBLi6iRIY+tGwQKQuJq0dmJDoj7s+v9ABII10zIFdmNMq9TdAmqV4hNP c3oWBFX/VA1hUAsA26JUwLlCghWcQQpvwt4OgWQxOPIZgLflkQqy4LjqHN2NH+jCsdOF OVVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BpbNKXRw; 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 f2-20020a170902ce8200b001675d8490e4si10368568plg.563.2022.06.13.09.31.46; Mon, 13 Jun 2022 09:32:00 -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=BpbNKXRw; 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 S1352571AbiFMLVo (ORCPT + 99 others); Mon, 13 Jun 2022 07:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353571AbiFMLQD (ORCPT ); Mon, 13 Jun 2022 07:16:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD11D3879C; Mon, 13 Jun 2022 03:38:23 -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 44AB860FFD; Mon, 13 Jun 2022 10:38:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 515DFC3411C; Mon, 13 Jun 2022 10:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116702; bh=JMZKYbB7nCqXYW9xB1J1ggXlqAWMiEs1FHKhNL29CG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpbNKXRwjqkx8k9+BEOcK4F/hDFHKmkX1+I7/MLYnfl82+xjusUfObXDD4iYC3D72 HzNDqKfp4jTxihlwpbsut6+2GfyGJhsMsd/C1J+xSrOUqDXD39N6q7kmT0bjMPW0lP jNEdaadJu1z/ArFe/2tMyurGP3LV1GCXSU085n0A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Neil Horman , Vlad Yasevich , Marcelo Ricardo Leitner , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 142/411] sctp: read sk->sk_bound_dev_if once in sctp_rcv() Date: Mon, 13 Jun 2022 12:06:55 +0200 Message-Id: <20220613094932.928407326@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 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 a20ea298071f46effa3aaf965bf9bb34c901db3f ] sctp_rcv() reads sk->sk_bound_dev_if twice while the socket is not locked. Another cpu could change this field under us. Fixes: 0fd9a65a76e8 ("[SCTP] Support SO_BINDTODEVICE socket option on incoming packets.") Signed-off-by: Eric Dumazet Cc: Neil Horman Cc: Vlad Yasevich Cc: Marcelo Ricardo Leitner Acked-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/sctp/input.c b/net/sctp/input.c index 9616b600a876..c306cb25f524 100644 --- a/net/sctp/input.c +++ b/net/sctp/input.c @@ -92,6 +92,7 @@ int sctp_rcv(struct sk_buff *skb) struct sctp_chunk *chunk; union sctp_addr src; union sctp_addr dest; + int bound_dev_if; int family; struct sctp_af *af; struct net *net = dev_net(skb->dev); @@ -169,7 +170,8 @@ int sctp_rcv(struct sk_buff *skb) * If a frame arrives on an interface and the receiving socket is * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB */ - if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb))) { + bound_dev_if = READ_ONCE(sk->sk_bound_dev_if); + if (bound_dev_if && (bound_dev_if != af->skb_iif(skb))) { if (transport) { sctp_transport_put(transport); asoc = NULL; -- 2.35.1