Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1768561imm; Thu, 27 Sep 2018 02:07:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV62yd8RBY4Cm2dwbVrMBHNC3NarujkCF4KtU269EK7TWbHC2FLywiGBxyRasZWupZOyCr1qr X-Received: by 2002:a17:902:509:: with SMTP id 9-v6mr10005445plf.155.1538039262554; Thu, 27 Sep 2018 02:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039262; cv=none; d=google.com; s=arc-20160816; b=ZlDAEookqPOFhuQ8JoT36/VxUlUgJC2WS3iWV3v644nFScNH9ovsifedsOxdDsDnT6 X7JDQUlrbqbHD83qm734VT94zxckhqnKueS0asBCS3pcAIsWNm4e2zYGVSFHzENZiWcH pyCJKX+7U04Dt0oMlceY5UPL4jH34LQaBnE0bsRYIzUngCRq8RUZZoS9ddEV3rTNiNfN H8PYtwyqNSRfV1XDOgub21lTp8kFN45txRVdk86fu9F6X0iqph1WxYKKy/qCei7I5Zxa aqFntLPVhKsgEFljaYtSWtlMsSAhkP+dsadzQJax+8+VVma/vna/7dF3IwFiDpo0yoLq rjcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=NiSe6rOZjOlq+1ksmIBnpikYPER+5TA5ty1/9S7W2nM=; b=XWbG5hhkqzPWv2VcDU9kNoYa7ry2CkyHBZDm9IIo0knXdzY6jNTaOBzvw/pMIMZEnY 2pp1CdBlUz3O3AjCt1DBiENngGh1PYycjIRByyGatICp4dNVCdo52tcEHWJsNUB2YFSF AaP0wook+92eDADRYxkT4lEbNvysRdsJQQb8YT37Z5OuB06921t+LKE2a6rZCF/DDQ2f efeKthzZjrN7kHo7XqUAx03aTLdmRd+QwKEuOoGJ3PvGLaK1Fgi7zCUB5leivecIEvTh uH5KyVG0QZ/7iM0vb1FlCn+YoqqFe3i661WSQ+kdqNCFkawPqoiGJnSZ7pSBY18/in3Q +uAw== 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 i2-v6si1682884pfe.334.2018.09.27.02.07.27; Thu, 27 Sep 2018 02:07:42 -0700 (PDT) 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 S1727354AbeI0PY0 (ORCPT + 99 others); Thu, 27 Sep 2018 11:24:26 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54712 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726944AbeI0PY0 (ORCPT ); Thu, 27 Sep 2018 11:24:26 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 726AB10C8; Thu, 27 Sep 2018 09:07:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 4.18 02/88] ipv6: fix possible use-after-free in ip6_xmit() Date: Thu, 27 Sep 2018 11:02:43 +0200 Message-Id: <20180927090300.881351924@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090300.631426620@linuxfoundation.org> References: <20180927090300.631426620@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit bbd6528d28c1b8e80832b3b018ec402b6f5c3215 ] In the unlikely case ip6_xmit() has to call skb_realloc_headroom(), we need to call skb_set_owner_w() before consuming original skb, otherwise we risk a use-after-free. Bring IPv6 in line with what we do in IPv4 to fix this. Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ip6_output.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -219,12 +219,10 @@ int ip6_xmit(const struct sock *sk, stru kfree_skb(skb); return -ENOBUFS; } + if (skb->sk) + skb_set_owner_w(skb2, skb->sk); consume_skb(skb); skb = skb2; - /* skb_set_owner_w() changes sk->sk_wmem_alloc atomically, - * it is safe to call in our context (socket lock not held) - */ - skb_set_owner_w(skb, (struct sock *)sk); } if (opt->opt_flen) ipv6_push_frag_opts(skb, opt, &proto);