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: 13447467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8735BC4167D for ; Mon, 6 Nov 2023 20:13:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FB3E6B02AF; Mon, 6 Nov 2023 15:13:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 683036B02B0; Mon, 6 Nov 2023 15:13:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 571596B02B1; Mon, 6 Nov 2023 15:13:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 489BF6B02AF for ; Mon, 6 Nov 2023 15:13:54 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 03537140874 for ; Mon, 6 Nov 2023 20:13:53 +0000 (UTC) X-FDA: 81428630388.20.DE3E617 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 0C7918000A for ; Mon, 6 Nov 2023 20:13:51 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="cb/DYhw0"; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699301632; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=e29xpsueqsta+pB4dpMwNezQWpITpFZrOcR7dgpqXnM=; b=p66tCInNvS9tktb4P3eBLSB8l14WavLt4Sy6JmshMAA5zetgtf5HfzdVT2gNxcZE6lDyRv TCDN/S/o/PjJVfbJkaakGW70oi8FxrnF3+LBFBuUW+nb7xtzD94b24r4NW89SJbyTmjine xUmFEkBHSb4RX0KSxXFm2dDCe2Za744= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699301632; a=rsa-sha256; cv=none; b=2Kjmqhojvff8fg6dAtCO4iqcwiPG/YMw8O0KR3+FXFNhpcVtBCSKCXCTeKIolCB6dBBNoF +XUsbagbFKvaHYE0kfYPgFVQ4m//aic/Hj1+ImbqrosWG0QjYMcrq5foEqC4l2MrJ2R6tM ohJJUWKpwF/a4g6f+670i6TruA/7+8k= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="cb/DYhw0"; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=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=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-Rspamd-Queue-Id: 0C7918000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dt1r7ud77496j7ymh4waqxp17ori1sec X-HE-Tag: 1699301631-949167 X-HE-Meta: U2FsdGVkX1+/bFTO7y7/3TqoyR+itQceeczYw437n1Q652pf/cGtk0uFaWCUyr6FdEpoE4eqUC2MguRZTw/kjrapkiVYCrelJDLGHll/CT3YCKKwQ7XWfA8daOLgxWPTNWuOib6a8AqdYwXq3sYTAgvkLTxfr6Gi+LPpC2IyqH1WDQb88mtFSWuhtNMCQa8yASBMFRZhUzatgnugT41XFnJN+nmSTlZFrM9RNZDY/YMNQtnKNa3rCQE+u17537uWW02hy0m9IagGjfGfFo47xaW6wT7m3rudx4uO8Dw5QmoRWJ7U/rhv6esRor1R2B0dvKrMbO4imIy7J//PseJPl2OeTp6AFX6pwLmllLbfSRMTUvjsgJspamU+syjnbv3wt2cNyMf99AcNn1MGfbC4+PtdH5dm3VIifQil2PL5t7f2mKWenhwatyLcmuEBOCqs6aY5UuF2ijB+d4VTmpuTgqKWkNnk1sJhNW8nod8jiCNdWSXZEKXlKAo9ls4Yu95ZtqIyVa4SWK+gFxDWQSUztRw8I2U3GWeWOX+80o86Lwxsysuc+l/RMuU3dV/upZoVmc+pRNW3ctGzSWmsRcSp2NbyiAQSE6IccTFdFGuATRcIKStlI+4SpmT4C0ykgYeqfdPmVGXqDr7lHcw4q4v8wboYQrSsehrmxlXbrJhH5zAOB2fr+XjQZ0pDM6cxF12naJfBGqmLC7WYFhytQK9KAtN6K59MGE7rTWcsz2ltmGHnfZCAH37xN9Ak6hhPR5+/C2+gG2EicLXb8nml9Sb+6dDFGCaOuy4FMc8xEEcJ1fwVm8cLJeN6MxM6wHS2SEApsrGNX+vuvVs38wdHvOdyJwS4w24iK7X4ytQmjIE+EHnZqufSV8M6CCHEVDPlzHtfj+7YSIYx+/epBPXPbABC9X6RLu+H/8IppoSZWMSLIB0noSba94TiC9PQ0H1f+ixTKv0MvlixQfMOrDaQSom Z1sTBcvp xdQImRF6VF8bVB5U5DzgQxr79CsmI/dGbzExZLaw6ZyV/O4bCQrnyBICpH9T+Of/96PUOgNL3JjEdjPvFceVe3pmfaIsdkzyLcYh0rmGoKca8TvYCr6G5WwkSZHb8IHsaWKiaXuKKwIHp6dtZEx/Wqpx4cm4FqI+OHkel0ASPPumer0KccpStj6zjY01k+q6JMuytBXeey1TTPcQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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);