From patchwork Mon Jun 13 20:13:52 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: 12880068 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 067E2C43334 for ; Mon, 13 Jun 2022 20:15:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5C408D01BF; Mon, 13 Jun 2022 16:15:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACBCD8D01C2; Mon, 13 Jun 2022 16:15:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FBA18D01BF; Mon, 13 Jun 2022 16:15:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 55BA98D01C0 for ; Mon, 13 Jun 2022 16:15:26 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 2F63180E9E for ; Mon, 13 Jun 2022 20:15:26 +0000 (UTC) X-FDA: 79574317452.26.AA18EF2 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf14.hostedemail.com (Postfix) with ESMTP id 79EA210006F for ; Mon, 13 Jun 2022 20:15:25 +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=1655151324; 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=M2+xlJvtrt/Ak+lac7lfuJjlG7HoHnjjsXRwZzO2wkQ=; b=D7+1mF++R9rQSyexDmLe4W43C6kZeCzNSBrDNdQTA+MttNF7gXjdHPZhzzpixGpWrrZc6t QTCBf0IP0biwlIgnvWlisHawkeaiNLKJyhDsmcZfG5NfvfKzCCHagM+dR5BuUGdO4uv0TP LRUfpmJCeWw5nPyMl1dFBPg0mKF7iiw= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 01/32] kasan: check KASAN_NO_FREE_META in __kasan_metadata_size Date: Mon, 13 Jun 2022 22:13:52 +0200 Message-Id: <91406e5f2a1c0a1fddfc4e7f17df22fda852591c.1655150842.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655151325; 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=M2+xlJvtrt/Ak+lac7lfuJjlG7HoHnjjsXRwZzO2wkQ=; b=BzGkwjW0xP3y03aIWoJgy5GK27mn3g3Je0bBwx7fvfHUDTvL2bLct8x7FjQ+/9d/kEI9hP 22eHJvzGWza6qT/O1hdEEkpXhWKdcHpEQgsk4W++3KkT8bn29ZMquLAw+/h4BfoeObF3kH EtuJ2glrNARuZK2xVibFVzMpgGF4Yg8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=D7+1mF++; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655151325; a=rsa-sha256; cv=none; b=n/kAggZsQ+rGNxFd86Wl7WA2gxhYipP/Fj03kxF1Bhbg1QY6NPDzQ1+gHuyZMe9HmYDCYL x08FnzFuSfVQc2p0h20nWu0EmktGMnku6qfXzyO7guzp86QanvZwSCr03P0nUAbDlWKwyG v2ZomCUs7xrssJD0iRiC72Y8P50iJno= X-Stat-Signature: 6c6wz8s74trcsstq815cpbjipg4dpsze X-Rspamd-Queue-Id: 79EA210006F X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=D7+1mF++; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-HE-Tag: 1655151325-951243 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(). Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- 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 c40c0e7b3b5f..968d2365d8c1 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -223,8 +223,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,