Received: by 10.223.185.116 with SMTP id b49csp6342910wrg; Wed, 28 Feb 2018 07:54:17 -0800 (PST) X-Google-Smtp-Source: AH8x226dmuFhm0/iu2KmVGaNIAMIHlBRRqVJtO6fj26U69vW5FTdLH88iPYQ95RiIgHDWu9a7b7c X-Received: by 10.98.205.140 with SMTP id o134mr18230015pfg.34.1519833256933; Wed, 28 Feb 2018 07:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833256; cv=none; d=google.com; s=arc-20160816; b=nFPExqaJRcv1nV9lFk4UMFZDIMPUaUTjzju/+3/dDvpNfNPuCUCGIaGR/uJQinMuPB 67hzoyWev40GBuqTSxwmag4phK0Zg706ar1t5TgYcl+qvyPIRWSYAdmEdZvsjWlAnmqZ 0x+41v4mZvvyh+/sxL6YhHy4CSqW40hIdWrD5Zaj5jDML7IobBxKBfvY+8Pb+m0Ms7a3 QZycvHaZADmDlTQRwfofMOzcJGnSjp/3tklJbrQtzexqZ62OESfFEljhScXms3dvmTwi nhWGPn+ZNC6IfyrQZJjzhJZ7TWZQFwqQdrKJHfuLKeHu8cu4rv0iPhiWXZcNsIWKeJMX PCsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=gH6t8KVYdteVhS+25pL8sOeXR80nnYDEELE5VfXlSls=; b=Z/Cp5T+3oAlMPAtYfAH+GpFl3hAp/F9niCH8iKgimbdQNxrw5a4FJR/vYZy0vGNkAH 1FSv1eiaBAtPF5HSA6FY0zLvPPoGlLzvNA4soMae4DEmnkpMF14s3SDO38lRdPFHkdgt yzUkyfnmLd2jI7Lt2FmGE8g+pAU/snIXfutIz/MBfObJrX4qLkdeoE/DCyEOvWhQAhES AQnhauuRm0L1u+mmYQ00nPWj1Py2q5jO0oWTDmj2TLXDBYyKBpVcQRRltAF7vtaDZDRE 7CU6xSPygmCe74vcfC954VCk2IfmbRUOTcgZSXbCR6adPViKwHWvhSLhDPqx9KEGpTPt fq1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j73si1130636pgc.566.2018.02.28.07.54.01; Wed, 28 Feb 2018 07:54:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933939AbeB1PxA (ORCPT + 99 others); Wed, 28 Feb 2018 10:53:00 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34423 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932426AbeB1Pw5 (ORCPT ); Wed, 28 Feb 2018 10:52:57 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yt-0006XT-HH; Wed, 28 Feb 2018 15:22:31 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yf-0008VW-OF; Wed, 28 Feb 2018 15:22:17 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mohamed Ghannam" , "David S. Miller" , "Eric Dumazet" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 088/254] net: ipv4: fix for a race condition in raw_sendmsg In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Mohamed Ghannam commit 8f659a03a0ba9289b9aeb9b4470e6fb263d6f483 upstream. inet->hdrincl is racy, and could lead to uninitialized stack pointer usage, so its value should be read only once. Fixes: c008ba5bdc9f ("ipv4: Avoid reading user iov twice after raw_probe_proto_opt") Signed-off-by: Mohamed Ghannam Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- net/ipv4/raw.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -490,11 +490,16 @@ static int raw_sendmsg(struct kiocb *ioc int err; struct ip_options_data opt_copy; struct raw_frag_vec rfv; + int hdrincl; err = -EMSGSIZE; if (len > 0xFFFF) goto out; + /* hdrincl should be READ_ONCE(inet->hdrincl) + * but READ_ONCE() doesn't work with bit fields + */ + hdrincl = inet->hdrincl; /* * Check the flags. */ @@ -569,7 +574,7 @@ static int raw_sendmsg(struct kiocb *ioc /* Linux does not mangle headers on raw sockets, * so that IP options + IP_HDRINCL is non-sense. */ - if (inet->hdrincl) + if (hdrincl) goto done; if (ipc.opt->opt.srr) { if (!daddr) @@ -591,12 +596,12 @@ static int raw_sendmsg(struct kiocb *ioc flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos, RT_SCOPE_UNIVERSE, - inet->hdrincl ? IPPROTO_RAW : sk->sk_protocol, + hdrincl ? IPPROTO_RAW : sk->sk_protocol, inet_sk_flowi_flags(sk) | - (inet->hdrincl ? FLOWI_FLAG_KNOWN_NH : 0), + (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0), daddr, saddr, 0, 0); - if (!inet->hdrincl) { + if (!hdrincl) { rfv.iov = msg->msg_iov; rfv.hlen = 0; @@ -621,7 +626,7 @@ static int raw_sendmsg(struct kiocb *ioc goto do_confirm; back_from_confirm: - if (inet->hdrincl) + if (hdrincl) err = raw_send_hdrinc(sk, &fl4, msg->msg_iov, len, &rt, msg->msg_flags);