Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp218096rdb; Tue, 19 Dec 2023 14:35:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBf02B1wa4mAMCaxNuYIcNCv+E12vXjDLjuGFAotHWKGyu60W/QsHraHhDjcdFzAof5G0d X-Received: by 2002:a7b:c390:0:b0:40b:5e59:e9fa with SMTP id s16-20020a7bc390000000b0040b5e59e9famr9377835wmj.153.1703025311987; Tue, 19 Dec 2023 14:35:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703025311; cv=none; d=google.com; s=arc-20160816; b=d2Q1mqiU2n9hth5RyPrLPbmQksopCwQHt8xDI/ol99bLeUl/deRrNlVIJQ4UXbCeLr x+Xu5rTrZ5cgvpw7kfzY0kEscUMzwnYJG7uU1q94PxaZpnkvhXLzKfV78WHdnIw3jULK Mlg0ahAd8blXJs2KRlV5RGrQPzyInpYCIZVwCe0BKKVVwTlWRE+P3kFGRDpyuNFKR1Ym ILZfQzZzperkCrR24934Iz6uiHxoWIwt42ZQSrUEE03zB/N4BWaz8xL8gZOaMkLQaWRQ QRiS3SCc3T55fylYVOUSgbgftvJgym5chJtg8T0mCAo0b0jCPP1ngzqI0g97uGWQ/pG6 nbYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=e29xpsueqsta+pB4dpMwNezQWpITpFZrOcR7dgpqXnM=; fh=AIzsiqkKUtrB7QnM+XRgAblgvDINIC5pDvD0mg8EzrU=; b=rz/qLWzNrMMnQw0d3FWeWBmvPYymv5VoHta6FRJBYGtfrTClrlljGPKp/9B52HTr/R uksuydQCFePC6+G7GI3/8ASRzT9nqmdjDAhpgohtvQGFENkVzDnimU6jlT4sgTSdtsM3 +mqPnklfCNR1ZDt/LpZKfA+9WsTT1rhFCKAywxiidEYCqubg9y/BhFvaH8OMc1DpXhBN CIR0mtR8yZ+KSNWTHYn1UtusYv8Mj/A/LHXfJw5RolbNS+MPPhSA2yU5F0jdbuO6JYWE UvcZLdUopJU2nCm+K/BtToOxXCHaSzLefcf+XktEd51LK1Qfx8gGhwk6pydykZl19qcu cwog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="ljf0/KaK"; spf=pass (google.com: domain of linux-kernel+bounces-6062-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6062-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v9-20020a1709063bc900b00a2346f18a73si2599447ejf.195.2023.12.19.14.35.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 14:35:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6062-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="ljf0/KaK"; spf=pass (google.com: domain of linux-kernel+bounces-6062-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6062-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7AB681F264BF for ; Tue, 19 Dec 2023 22:35:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBF8F4D58B; Tue, 19 Dec 2023 22:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ljf0/KaK" X-Original-To: linux-kernel@vger.kernel.org Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03BEB4CB22 for ; Tue, 19 Dec 2023 22:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703025149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e29xpsueqsta+pB4dpMwNezQWpITpFZrOcR7dgpqXnM=; b=ljf0/KaKFmDC2Uyj9pcq18seQDB62a/kgliZneYzRVKag4kgTWvduY54lnptev/4IOVTKg XWh9fADptQruk8bYRvzl+jF0l8p4U0RNpQ3xZT3+C7DxlLuZnVWmBR0/EtI5V5z/V058ga q4EXpOfTgh0O1XTzevXYooHK4dHrhlQ= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Breno Leitao , Alexander Lobakin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 20/21] skbuff: use mempool KASAN hooks Date: Tue, 19 Dec 2023 23:29:04 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Andrey Konovalov Instead of using slab-internal KASAN hooks for poisoning and unpoisoning cached objects, use the proper mempool KASAN hooks. Also check the return value of kasan_mempool_poison_object to prevent double-free and invali-free bugs. Signed-off-by: Andrey Konovalov --- net/core/skbuff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 63bb6526399d..bb75b4272992 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -337,7 +337,7 @@ static struct sk_buff *napi_skb_cache_get(void) } skb = nc->skb_cache[--nc->skb_count]; - kasan_unpoison_new_object(skbuff_cache, skb); + kasan_mempool_unpoison_object(skb, kmem_cache_size(skbuff_cache)); return skb; } @@ -1309,13 +1309,15 @@ static void napi_skb_cache_put(struct sk_buff *skb) struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache); u32 i; - kasan_poison_new_object(skbuff_cache, skb); + if (!kasan_mempool_poison_object(skb)) + return; + nc->skb_cache[nc->skb_count++] = skb; if (unlikely(nc->skb_count == NAPI_SKB_CACHE_SIZE)) { for (i = NAPI_SKB_CACHE_HALF; i < NAPI_SKB_CACHE_SIZE; i++) - kasan_unpoison_new_object(skbuff_cache, - nc->skb_cache[i]); + kasan_mempool_unpoison_object(nc->skb_cache[i], + kmem_cache_size(skbuff_cache)); kmem_cache_free_bulk(skbuff_cache, NAPI_SKB_CACHE_HALF, nc->skb_cache + NAPI_SKB_CACHE_HALF); -- 2.25.1