From patchwork Mon Nov 6 20:10:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 162174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2903578vqu; Mon, 6 Nov 2023 12:15:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IERO6HIJFvZGtQ2RC/Cqza5zBi6q25ZmlibWPlv6WPXDxiegB6scH55mnd1/jP2wwVijInh X-Received: by 2002:a05:6358:c3a1:b0:168:f48f:4414 with SMTP id fl33-20020a056358c3a100b00168f48f4414mr28564745rwb.25.1699301701483; Mon, 06 Nov 2023 12:15:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301701; cv=none; d=google.com; s=arc-20160816; b=x0AsJ1Z3VSjE5o5F+5+Npkbd3Oddud5AjvbI71hTpI3/chseplAUAv4GeyB0mAa6/I EmlV/EpGmJEQ5OmKwlpp54+azDpfgGgvqw680wzeYfGflF/BSfI7AUitrCgLbxLnGiN8 HJwFU1XmSWUF4nD8ceTXEWW+umuV4VpRMQzbcNNPhfqEB04yAmTwulEcO5c/98dnKNYZ /kRI2HvWWq/qRtm8hGyIDqKqQwiPxFNZAV1o6wMyndsIHh/Lg8W7TMNoatALMTHPjdvD GnTNOV5mn5V3/5QLxjM/+wcNPwYCCKUqQL0XZFMOJGdxw7OlE7/1+lgzAkaba4tA5405 H0eg== 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:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f7-20020a656287000000b00578af609d05si392947pgv.244.2023.11.06.12.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:15:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; 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:2 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 agentk.vger.email (Postfix) with ESMTP id CD0F980320CD; Mon, 6 Nov 2023 12:14:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232990AbjKFUOf (ORCPT + 34 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 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:14:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781846980559068450 X-GMAIL-MSGID: 1781846980559068450 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);