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 6D66DC28EBD for ; Sun, 9 Jun 2019 17:20:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E29920652 for ; Sun, 9 Jun 2019 17:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560100827; bh=sdE3P7sOxxmzEGlCIbI3UmAgN/aiH7Yp1z0Sp9FfpiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0klAm0xG8UA09b93FCe0MigZ1dOxRiNC3zy4GYSqkWMsJDxO2Z9oE0XO+DxAYm9ej uZ5zUTemwYr0vZwlzgORpK+y6LrzMDU1j5h21i3hUutfOgJfGybeFMv0WOGuF7MYXH lE/GCTo2JQ9nIPus/u9FdKZ5QkMySBX2LwtZinck= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730839AbfFIQrk (ORCPT ); Sun, 9 Jun 2019 12:47:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:46376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730910AbfFIQrj (ORCPT ); Sun, 9 Jun 2019 12:47:39 -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 BA409205ED; Sun, 9 Jun 2019 16:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560098859; bh=sdE3P7sOxxmzEGlCIbI3UmAgN/aiH7Yp1z0Sp9FfpiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hjzID1LQGlGyzSbq4tDV68WEtk/uNsg5KycjVLMUY4cciyoxyZc6cLbjggYis7OeH iVnIZH+m9rNMaqTFbWuod7Khr09OcRMnEVM4oC+REIodpWNfGVCOCfnX9jqFNLyu0P xz7Y2iV1gwg3OGV1MTxSneXM8JnzOxTjEoBTCHMc= 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.19 15/51] ipv6: use READ_ONCE() for inet->hdrincl as in ipv4 Date: Sun, 9 Jun 2019 18:41:56 +0200 Message-Id: <20190609164127.967317205@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.123076536@linuxfoundation.org> References: <20190609164127.123076536@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 @@ -782,6 +782,7 @@ static int rawv6_sendmsg(struct sock *sk struct flowi6 fl6; struct ipcm6_cookie ipc6; int addr_len = msg->msg_namelen; + int hdrincl; u16 proto; int err; @@ -795,6 +796,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. */ @@ -907,7 +915,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) @@ -930,7 +938,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, &ipc6.sockc); else {