Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2376703rdf; Mon, 6 Nov 2023 12:14:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHejlrtalxPXGuoSD6q4AfSiC9tXgKP7ZIPMX/KeNEzyKS9VL5K5X+ixIhW3K6z5HiHm3g X-Received: by 2002:a05:6358:528b:b0:169:98e4:ae85 with SMTP id g11-20020a056358528b00b0016998e4ae85mr23028604rwa.24.1699301684509; Mon, 06 Nov 2023 12:14:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301684; cv=none; d=google.com; s=arc-20160816; b=yWpFF0oZdMMhME4YU+Nh8OMW43EluFvkL22nHFzEm7gxH+EPwG0PRgaLkdHeuJTlA+ ngf0IWDtB2fVz8m1EBCIa/qokndJ/CqTRzNKQTWCFMc3cJ7GUpECj39fHxVobetVGXfz 5knQ43tA8cq3/4M82OUnaNmtmXYhUImgXgickCHQ2WTEgSc7HvJzijAhL4mMJUp+Dkri 6VuwnjjV2XnEFlKyVbX1zi64wAwkfMNI0OK15VaQZKFWc7HDn5bGExSQzXJGhKv5fReO EQl559ZkSjTYcGVHbA4KztSYYk4dWN3kSORjkc5We63T6jwiWpZK4Wqcg6AIcVoBOrGR VDSw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e29xpsueqsta+pB4dpMwNezQWpITpFZrOcR7dgpqXnM=; fh=n5KN85tQTomq0Sa/nFFC9xbnc77mxkBzF8HoolO/QOw=; b=hLaQNX4gpYQLEgoXR41uoMvYCQ4xHcLWcY4+qx+RNynviAhjNB5xmJXeOlxRU5rjmd 7umtYNG/jRpCuhUCCVcLXsIxdPRtsWbDxjL0AHkjDMeLTYq+efLqiMLHEwhqj4xr7RIj hL1wAZeqiD7QKdnivaDmk2/07NwZzsRYyzDlpVz0/0KgvaOWHm0cp0WIlI0r1IC0aVvz 0lVil3+dIZoTsagJz5+LLdZJlUAXGXev/FR2Ghdo2LRzbyiJA1nT9g+9OedIZE3rJnqb FjDIl8TxDfymmJOFycRYtCh29YM4bT4Pf+OXyhlH3SEB2iN739HIhAQlXiTczEUhA/DV p9iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="cb/DYhw0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bj6-20020a056a02018600b00564c67e66fbsi459652pgb.842.2023.11.06.12.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:14:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="cb/DYhw0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 946AE801B9DD; Mon, 6 Nov 2023 12:14:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbjKFUOf (ORCPT + 99 others); Mon, 6 Nov 2023 15:14:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233158AbjKFUOO (ORCPT ); Mon, 6 Nov 2023 15:14:14 -0500 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [IPv6:2001:41d0:1004:224b::ae]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260671986 for ; Mon, 6 Nov 2023 12:13:52 -0800 (PST) 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=1699301630; 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=cb/DYhw0AcKTI1pVz3p5Uc8ghHAi9yPw0pCvEZBvaYr82je3xMtKhMD9iTFLNv661L48Eq HUw3/4UfBzgyqKFgTfXOU3WP5GDlN3MF7k6C82pIbPfG6hYKtEzn5y09GxVAaKf1nIbuQV MZc8fQIvmv/Ni7E4wK5ggRDzTvGHEZ0= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH RFC 19/20] skbuff: use mempool KASAN hooks Date: Mon, 6 Nov 2023 21:10:28 +0100 Message-Id: <13e15a27958e63070970ca4d7bb52c8c156bfa02.1699297309.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:14:43 -0800 (PST) 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