Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3712883pxv; Mon, 26 Jul 2021 10:02:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfmZfnuU1Hw2LqAePLaeQR3riouWKV1KLlZmE7em2CfMcUzAR8rkIJYNyC8edHnADLPzuO X-Received: by 2002:a05:6402:1c10:: with SMTP id ck16mr22155734edb.339.1627318932854; Mon, 26 Jul 2021 10:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318932; cv=none; d=google.com; s=arc-20160816; b=B0JElrL29oS1pCP1nrmuzuXhE5uzE6Ul8KwC58WEzI9PaELkdR3a3PnnBgoqg4b4Th JIhPH4zxEtL3odIET3vCLi44c3pZAmhxVbJqN9rrMbALtt+/L37OdK0YuKXdtspy60Gl U61DUfZRU0goIVJSAocY4+z34PIVjdnUzxOkrzNo2F5jXOCJ9HBZNBfl2zvhRPPUBHWj Y9uB6Nm/pMPdWp3M68wcUcFvXR9y4RwNgM+TkZUZGwNuvZrVtwZUqyDONf7yvyG4/+jd xPKNlsJR5cYjDqXks9u65oJeDe+SRXN0AOCL2fUe5w+1BkrfrQxCgn/NVccVP3+iN/Bs tgtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3c6QaPUKXyRiHEWdCaJ/fL3LTkgQPK5WS3/YCklwh0M=; b=CD9aAmzxLqjVGnISCOFRrmDTdVJH2LrLeGdNHYPB+/Ekh3dkjlCkjfUXLa5R/Bl0Dc BSwn7O+qf257MgfJ+mJA4d3v/0Vt5Hh6P4LoLDnFAVyqk47CNhs05zAOXW1zTkr/kpVn FQj+yeB1n6xC9ZnCfAwJZmnPKoFS3hURu8jr8nMoBZsR8+Q4XacUYeD33WAWyvRtrS7v AIHSYAZ2J4chtHKXxJLDZNAegJj9gV+5ud/n1GA2JIzzOYK56Z67W4f3m4esfVn0S61M vljHXcXvnhj1C0bov/cKpC4KzKz46LlhYxK2so4a+i1MedObuo/oCV+vAo8KD5/NJ3CB dOuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mGSyfjZw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si499845edi.248.2021.07.26.10.01.40; Mon, 26 Jul 2021 10:02:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mGSyfjZw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231909AbhGZPfp (ORCPT + 99 others); Mon, 26 Jul 2021 11:35:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:34268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237056AbhGZPUi (ORCPT ); Mon, 26 Jul 2021 11:20:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75E5B60E09; Mon, 26 Jul 2021 16:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315267; bh=t+368inyZXG7DCMhc4qa3uvkQfiW/mX7WJ+EOKEMkzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mGSyfjZwqCRY2mt5EmxNOcIi0gvoGC5daIZy+ubi2aATDOhSyBWKh5KOP0q+nQs2K QJNSBvcsIp/qOZuBoje4mGVkk02kE4PDPRE8nFuaXntVg2TH5psGK6LeJdx1LWOMME lgGAALWfsV5cj8W+Jk4zWH/+dJiGFVEZf7daySS0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Lobakin , Antoine Tenart , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 029/167] net: do not reuse skbuff allocated from skbuff_fclone_cache in the skb cache Date: Mon, 26 Jul 2021 17:37:42 +0200 Message-Id: <20210726153840.350300456@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Antoine Tenart [ Upstream commit 28b34f01a73435a754956ebae826e728c03ffa38 ] Some socket buffers allocated in the fclone cache (in __alloc_skb) can end-up in the following path[1]: napi_skb_finish __kfree_skb_defer napi_skb_cache_put The issue is napi_skb_cache_put is not fclone friendly and will put those skbuff in the skb cache to be reused later, although this cache only expects skbuff allocated from skbuff_head_cache. When this happens the skbuff is eventually freed using the wrong origin cache, and we can see traces similar to: [ 1223.947534] cache_from_obj: Wrong slab cache. skbuff_head_cache but object is from skbuff_fclone_cache [ 1223.948895] WARNING: CPU: 3 PID: 0 at mm/slab.h:442 kmem_cache_free+0x251/0x3e0 [ 1223.950211] Modules linked in: [ 1223.950680] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 5.13.0+ #474 [ 1223.951587] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-3.fc34 04/01/2014 [ 1223.953060] RIP: 0010:kmem_cache_free+0x251/0x3e0 Leading sometimes to other memory related issues. Fix this by using __kfree_skb for fclone skbuff, similar to what is done the other place __kfree_skb_defer is called. [1] At least in setups using veth pairs and tunnels. Building a kernel with KASAN we can for example see packets allocated in sk_stream_alloc_skb hit the above path and later the issue arises when the skbuff is reused. Fixes: 9243adfc311a ("skbuff: queue NAPI_MERGED_FREE skbs into NAPI cache instead of freeing") Cc: Alexander Lobakin Signed-off-by: Antoine Tenart Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 6b08de52bf0e..86a0fe0f4c02 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6100,6 +6100,8 @@ static gro_result_t napi_skb_finish(struct napi_struct *napi, case GRO_MERGED_FREE: if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) napi_skb_free_stolen_head(skb); + else if (skb->fclone != SKB_FCLONE_UNAVAILABLE) + __kfree_skb(skb); else __kfree_skb(skb); break; -- 2.30.2