Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp651025img; Fri, 22 Mar 2019 05:57:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYonog7WU+6L6JlpWd1TuGAuwf4GwY/9L2JJ+mkqrtvaDTI3hIh2lMhV4oI10W2BmWoCJp X-Received: by 2002:a65:6105:: with SMTP id z5mr8893114pgu.434.1553259471301; Fri, 22 Mar 2019 05:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553259471; cv=none; d=google.com; s=arc-20160816; b=uJlxwZl+Is2OqFIJP2ry/oBtX6woSSLxsY/VuN1vWX07MDHxbrpTcRHVsuex8Y1eRq kRuNyVOyN9in9sWKiCsvT5nxf+mUTor7hxzKpshp19Y3f+0Pj17fzHyYYFEYq981TGmv LeyqyQL2drdDnM9DAWPuYV5fKaZRGhVIfm+6OTW2ysq4+21OQ3ILK4VdNg5Nt92T0lrr epjJJgYj7+uj95dNH8fLA8W6i1izmjgxzz93zve2v94u14rrn3X7nE6CM8Ex0HwW5FE8 TVaoAcjdKoS6Ls1Bx1U3xwGAtZq18HRYPi7JTtOa5v0M0lcNYkBxuPfSwR1jlmgJ35vI WPMw== 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:dkim-signature; bh=yavVyutqovC0pOR7u2jWI3b7g28BPf1/yuYiKjMpRbM=; b=eIvkob4lwuxtTv8ksxjgNxEeBe/uMLOTMMp81BxzTL6yHVMdz4rGC/yTltt0AdMGQY soSi3EA4G1eTIC6X/ngcdSN0wCQVQgpblMPavt2jdcfSRW8z7uBRwGNf6eguXVQiiLiK tuayG13fR0OOU3VOexyAXRwe94qaK+6xIkpVhJP8co4QTFWAmnTBhKPuzuCN6I1wIl64 3ghomqjmZMypzT7KEbPL2S+NCgL7jfQp1xyOlSadViUNwd6rBnvUkghUhVbubtMcmQrz 6NuZZTPlzaqycQLXdFh/0/jKEFcTGDhTmqFxYcH3UkwKvwUC/caT0EfzJtfvspLMTVsr ptrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aa5ZIv2h; 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 f35si7248131plh.152.2019.03.22.05.57.36; Fri, 22 Mar 2019 05:57:51 -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; dkim=pass header.i=@kernel.org header.s=default header.b=aa5ZIv2h; 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 S1732196AbfCVLs4 (ORCPT + 99 others); Fri, 22 Mar 2019 07:48:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:52292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732356AbfCVLsw (ORCPT ); Fri, 22 Mar 2019 07:48:52 -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 5B2E1218B0; Fri, 22 Mar 2019 11:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255331; bh=A4I4m9koCuXfB6FpWU/fob3Gb6j4XE5dFR9qnJdjaPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aa5ZIv2h8yAIQBXMJDSpFRvYifRAS30/JjrKKuD2SVqmoRboWu75Ziqd+1qkUVQk7 tDwOSalXlhKFxTpV0ZNJqG1EtXnEHXdPp0lLrgk42bxjjJSdochCzkT7qC3kgLbQwF o4ZbM6l2VwVWQcFs6M119ECQ0l584ln1oSWxHPas= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Willi , Steffen Klassert , Sasha Levin Subject: [PATCH 4.14 039/183] esp: Skip TX bytes accounting when sending from a request socket Date: Fri, 22 Mar 2019 12:14:27 +0100 Message-Id: <20190322111244.555727953@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111241.819468003@linuxfoundation.org> References: <20190322111241.819468003@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 09db51241118aeb06e1c8cd393b45879ce099b36 ] On ESP output, sk_wmem_alloc is incremented for the added padding if a socket is associated to the skb. When replying with TCP SYNACKs over IPsec, the associated sk is a casted request socket, only. Increasing sk_wmem_alloc on a request socket results in a write at an arbitrary struct offset. In the best case, this produces the following WARNING: WARNING: CPU: 1 PID: 0 at lib/refcount.c:102 esp_output_head+0x2e4/0x308 [esp4] refcount_t: addition on 0; use-after-free. CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.0.0-rc3 #2 Hardware name: Marvell Armada 380/385 (Device Tree) [...] [] (esp_output_head [esp4]) from [] (esp_output+0xb8/0x180 [esp4]) [] (esp_output [esp4]) from [] (xfrm_output_resume+0x558/0x664) [] (xfrm_output_resume) from [] (xfrm4_output+0x44/0xc4) [] (xfrm4_output) from [] (tcp_v4_send_synack+0xa8/0xe8) [] (tcp_v4_send_synack) from [] (tcp_conn_request+0x7f4/0x948) [] (tcp_conn_request) from [] (tcp_rcv_state_process+0x2a0/0xe64) [] (tcp_rcv_state_process) from [] (tcp_v4_do_rcv+0xf0/0x1f4) [] (tcp_v4_do_rcv) from [] (tcp_v4_rcv+0xdb8/0xe20) [] (tcp_v4_rcv) from [] (ip_protocol_deliver_rcu+0x2c/0x2dc) [] (ip_protocol_deliver_rcu) from [] (ip_local_deliver_finish+0x48/0x54) [] (ip_local_deliver_finish) from [] (ip_local_deliver+0x54/0xec) [] (ip_local_deliver) from [] (ip_rcv+0x48/0xb8) [] (ip_rcv) from [] (__netif_receive_skb_one_core+0x50/0x6c) [...] The issue triggers only when not using TCP syncookies, as for syncookies no socket is associated. Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible") Signed-off-by: Martin Willi Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index b00e4a43b4dc..d30285c5d52d 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -307,7 +307,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * skb->len += tailen; skb->data_len += tailen; skb->truesize += tailen; - if (sk) + if (sk && sk_fullsock(sk)) refcount_add(tailen, &sk->sk_wmem_alloc); goto out; diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index f112fef79216..ef7822fad0fd 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -275,7 +275,7 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info skb->len += tailen; skb->data_len += tailen; skb->truesize += tailen; - if (sk) + if (sk && sk_fullsock(sk)) refcount_add(tailen, &sk->sk_wmem_alloc); goto out; -- 2.19.1