From patchwork Mon Sep 5 21:05:16 2022 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: 12966540 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 03243ECAAD3 for ; Mon, 5 Sep 2022 21:05:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F068680208; Mon, 5 Sep 2022 17:05:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA3C7801E6; Mon, 5 Sep 2022 17:05:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D545B80208; Mon, 5 Sep 2022 17:05:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C3DDB801E6 for ; Mon, 5 Sep 2022 17:05:55 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9E4DE1A04E8 for ; Mon, 5 Sep 2022 21:05:55 +0000 (UTC) X-FDA: 79879263870.22.EB34615 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf12.hostedemail.com (Postfix) with ESMTP id 4BC8B40086 for ; Mon, 5 Sep 2022 21:05:55 +0000 (UTC) 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=1662411954; 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=VgD6aAPrK9DNDeYC6eoXfhD6gN4R30dJg8cA4lzePd8=; b=RxlSmPaRnwqLOjBsj2drvAj3zg8whhn2psRNh9NwetZna2QIK8hXbosD90G6O0Ezwk2Vb8 +cl3ju3ie7yPorJ/l2CiqTcbkoRoGpW/9uTb+dlsX2EwI2U9McjKOFN6e39iMoJchOFI1T bcSRI7JNrp9c0K5qSvvXgVNJMjtiNNk= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm v3 01/34] kasan: check KASAN_NO_FREE_META in __kasan_metadata_size Date: Mon, 5 Sep 2022 23:05:16 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662411955; a=rsa-sha256; cv=none; b=Lx2ANj2mD63S9oeIzmv8Tp28FSIuZSTyCB41TN+Lf5bl196kd1Rup8V9aZXM3HtY8ScjDq z4WNf9mAWImd7qXSiwMt+VK5lQs4G1vDckl4qPBzqtYhiC6XFxXfoEe1CGZDdSuA7cMcEI CHLUtDurgxYQXFNjyTJmlS9nXAhsJDA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=RxlSmPaR; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 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=1662411955; 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=VgD6aAPrK9DNDeYC6eoXfhD6gN4R30dJg8cA4lzePd8=; b=GtH73XKhvwS13jyx3qAkFMDECJ0oAju/0xcqVZT3+b5W4pyUZjYuST1GQfJ9in0xupA0kk yZVayNeTIcQZ2DfFa1M0U0nlEnOF26/oXR8fzBVm+h6/AEe7tvdMsQ0mn6O5onH0VYe5gt vYVIpuZ6XODytAyggsX6Rf+Nm7n/jSg= Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=RxlSmPaR; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Server: rspam01 X-Rspam-User: X-Stat-Signature: yhh7w61dbddzoou5kq8er6tpq1wimwc6 X-Rspamd-Queue-Id: 4BC8B40086 X-HE-Tag: 1662411955-82496 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: From: Andrey Konovalov __kasan_metadata_size() calculates the size of the redzone for objects in a slab cache. When accounting for presence of kasan_free_meta in the redzone, this function only compares free_meta_offset with 0. But free_meta_offset could also be equal to KASAN_NO_FREE_META, which indicates that kasan_free_meta is not present at all. Add a comparison with KASAN_NO_FREE_META into __kasan_metadata_size(). Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- This is a minor fix that only affects slub_debug runs, so it is probably not worth backporting. --- mm/kasan/common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 69f583855c8b..f6a6c7d0d8b8 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -224,8 +224,9 @@ size_t __kasan_metadata_size(struct kmem_cache *cache) return 0; return (cache->kasan_info.alloc_meta_offset ? sizeof(struct kasan_alloc_meta) : 0) + - (cache->kasan_info.free_meta_offset ? - sizeof(struct kasan_free_meta) : 0); + ((cache->kasan_info.free_meta_offset && + cache->kasan_info.free_meta_offset != KASAN_NO_FREE_META) ? + sizeof(struct kasan_free_meta) : 0); } struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache,