Received: by 2002:a25:730a:0:0:0:0:0 with SMTP id o10csp596849ybc; Thu, 3 Oct 2019 09:19:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZP6ZLVgwBtdkFcXAewQSZ/Pdl6CCBN88WjykY12CWh4vN8paXJU3DHYyP48ToQjCC3ebp X-Received: by 2002:a17:906:b298:: with SMTP id q24mr8474424ejz.168.1570119571223; Thu, 03 Oct 2019 09:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570119571; cv=none; d=google.com; s=arc-20160816; b=cWwFedLoAJn0vRwENpDwVfQC42Bhu5NjoybqhVemn1XUQtyMaJdFjOR/AUmLdBsHT7 mpuogs+n7YAVNFf1BvXkI3PX0h+CiEIX5GKWvdS20HcwRIlYdJAToHjB7xsbEXxVI03C 8TcMI+k66OwPqrXkjRIYCrDa7YTk4CBk3GPdQiKigjSWPStOJuBBaC2tf0H7NEkNo/zD O3VIGcejd+pvPPX9z6UquBTU2iVqtpxkaBcGnrcCpD4SQNgU7KLlm8090/g98IeaIHXY ogA71lgVSNwcWpwwYwl2vEZN+CzGejtj9JmLTEkXCB7rL5NPQG2YEamlSw1idAujBGgB ShvA== 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=Vxl5DO54pRzrOt/ImxCoxi3X4ufQCSamvEfkOjRxinw=; b=bBNtVhY8sObpkMMgD+sKFQYvPL536Am5s/+5gaD/V1BfZr9Jp9+u3l3k0j0xrTuZgP QfZyTthNDOAITLlX25qH4r2T7JOWGvGFUjR6KHEa8Hm/F1BUeDxEpXUTqLlu46hvkgZF KX3RnSY1aTTx2CY6Q7E6Gb85lNji3H/pGezD4pAjDaYPLkFpQkPrICLXsMAEh2KhhUvN ypCIS2wZa45Q0pewAF6ArOxbfMTOBEP1Q1oSSJX/mXhBuZ4ZNI4RcQwOT4XmFlO7S0rv 6Xqc/cJsEr1nw/hqJwmp5a4OGTZuc14iJ+plmicAypp+ZsxU7+zOt16AOKWB8DLGTsB4 Odvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PgxhYWJ8; 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 h20si1713782edb.218.2019.10.03.09.19.06; Thu, 03 Oct 2019 09:19:31 -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=PgxhYWJ8; 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 S2388308AbfJCQPk (ORCPT + 99 others); Thu, 3 Oct 2019 12:15:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:39930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732566AbfJCQPj (ORCPT ); Thu, 3 Oct 2019 12:15: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 178ED20700; Thu, 3 Oct 2019 16:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119338; bh=BwIqEIHAFRGX7m8m0TfqC8bEZ2qfLxB+Kv6uE2zcoDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PgxhYWJ8MwqdU03u6Csxkxzo9GXpFhIasqnG/nXYLgl71eXNCIbRyKpZEkh/CMvHY iOpFpnepPMLGyEwBxb4GVtQxoDdtEPrWxwsKMqA8R0uBpK6yrysfRJOqunxIGdVMLx wtYBwuH+x8ViUNQ2YUNpeFqY+8vLbn7I7ETKhyv0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiumei Mu , Fei Liu , Xin Long , "David S. Miller" Subject: [PATCH 4.19 003/211] macsec: drop skb sk before calling gro_cells_receive Date: Thu, 3 Oct 2019 17:51:09 +0200 Message-Id: <20191003154447.921813005@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Xin Long [ Upstream commit ba56d8ce38c8252fff5b745db3899cf092578ede ] Fei Liu reported a crash when doing netperf on a topo of macsec dev over veth: [ 448.919128] refcount_t: underflow; use-after-free. [ 449.090460] Call trace: [ 449.092895] refcount_sub_and_test+0xb4/0xc0 [ 449.097155] tcp_wfree+0x2c/0x150 [ 449.100460] ip_rcv+0x1d4/0x3a8 [ 449.103591] __netif_receive_skb_core+0x554/0xae0 [ 449.108282] __netif_receive_skb+0x28/0x78 [ 449.112366] netif_receive_skb_internal+0x54/0x100 [ 449.117144] napi_gro_complete+0x70/0xc0 [ 449.121054] napi_gro_flush+0x6c/0x90 [ 449.124703] napi_complete_done+0x50/0x130 [ 449.128788] gro_cell_poll+0x8c/0xa8 [ 449.132351] net_rx_action+0x16c/0x3f8 [ 449.136088] __do_softirq+0x128/0x320 The issue was caused by skb's true_size changed without its sk's sk_wmem_alloc increased in tcp/skb_gro_receive(). Later when the skb is being freed and the skb's truesize is subtracted from its sk's sk_wmem_alloc in tcp_wfree(), underflow occurs. macsec is calling gro_cells_receive() to receive a packet, which actually requires skb->sk to be NULL. However when macsec dev is over veth, it's possible the skb->sk is still set if the skb was not unshared or expanded from the peer veth. ip_rcv() is calling skb_orphan() to drop the skb's sk for tproxy, but it is too late for macsec's calling gro_cells_receive(). So fix it by dropping the skb's sk earlier on rx path of macsec. Fixes: 5491e7c6b1a9 ("macsec: enable GRO and RPS on macsec devices") Reported-by: Xiumei Mu Reported-by: Fei Liu Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/macsec.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -1238,6 +1238,7 @@ deliver: macsec_rxsa_put(rx_sa); macsec_rxsc_put(rx_sc); + skb_orphan(skb); ret = gro_cells_receive(&macsec->gro_cells, skb); if (ret == NET_RX_SUCCESS) count_rx(dev, skb->len);