From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C717C28EBD for ; Sun, 9 Jun 2019 17:15:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73409205F4 for ; Sun, 9 Jun 2019 17:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560100542; bh=GaK5bodEMpnjuCxoFdhWYcoPSFD4LwikbbsaoZE2hbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Wt4xxioKqFhfhcV6fd6Oce2k+cNNpgxL5NR6S8DQkEFezzGATzGtXOOEP7z2xNQin Q2AxjhpbAhLwj9RlTLlOhSIkC6WjpbQmtsYBjge4vLwQl4nrhzN3HDB8Q96oTa5dF4 CTk6nNTNtAl/iPCs7JcEv9mvQcLxHwMDfrIggfBQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732141AbfFIQyW (ORCPT ); Sun, 9 Jun 2019 12:54:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732583AbfFIQyW (ORCPT ); Sun, 9 Jun 2019 12:54:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6BF4B206BB; Sun, 9 Jun 2019 16:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099261; bh=GaK5bodEMpnjuCxoFdhWYcoPSFD4LwikbbsaoZE2hbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/woSCit+hJMkfmrhuvQFgd68Dx3ec+5z/ZXzlGJVeU/8wEEUERY8qFSTUXpADX8O QZg4CTrGIPHvA7xe7jHi61iksJHGvy3/397IjMZ2weR/v8gNHaDsSEUSErMtJOuQ2f ZTyqTQustKgzCuStxzLxOhMCv3Tk6axX7rLVv08M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Olivier Matz , "David S. Miller" Subject: [PATCH 4.9 68/83] ipv6: use READ_ONCE() for inet->hdrincl as in ipv4 Date: Sun, 9 Jun 2019 18:42:38 +0200 Message-Id: <20190609164133.591210838@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.843327870@linuxfoundation.org> References: <20190609164127.843327870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Olivier Matz [ Upstream commit 59e3e4b52663a9d97efbce7307f62e4bc5c9ce91 ] As it was done in commit 8f659a03a0ba ("net: ipv4: fix for a race condition in raw_sendmsg") and commit 20b50d79974e ("net: ipv4: emulate READ_ONCE() on ->hdrincl bit-field in raw_sendmsg()") for ipv4, copy the value of inet->hdrincl in a local variable, to avoid introducing a race condition in the next commit. Signed-off-by: Olivier Matz Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/raw.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -774,6 +774,7 @@ static int rawv6_sendmsg(struct sock *sk struct sockcm_cookie sockc; struct ipcm6_cookie ipc6; int addr_len = msg->msg_namelen; + int hdrincl; u16 proto; int err; @@ -787,6 +788,13 @@ static int rawv6_sendmsg(struct sock *sk if (msg->msg_flags & MSG_OOB) return -EOPNOTSUPP; + /* hdrincl should be READ_ONCE(inet->hdrincl) + * but READ_ONCE() doesn't work with bit fields. + * Doing this indirectly yields the same result. + */ + hdrincl = inet->hdrincl; + hdrincl = READ_ONCE(hdrincl); + /* * Get and verify the address. */ @@ -904,7 +912,7 @@ static int rawv6_sendmsg(struct sock *sk fl6.flowi6_oif = np->ucast_oif; security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); - if (inet->hdrincl) + if (hdrincl) fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH; if (ipc6.tclass < 0) @@ -927,7 +935,7 @@ static int rawv6_sendmsg(struct sock *sk goto do_confirm; back_from_confirm: - if (inet->hdrincl) + if (hdrincl) err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst, msg->msg_flags); else { ipc6.opt = opt;