From patchwork Tue Jul 19 00:09:41 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: 12921894 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 AA32CC433EF for ; Tue, 19 Jul 2022 00:10:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B46E76B0071; Mon, 18 Jul 2022 20:10:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACDFE6B0073; Mon, 18 Jul 2022 20:10:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9966E6B0074; Mon, 18 Jul 2022 20:10:21 -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 868B46B0071 for ; Mon, 18 Jul 2022 20:10:21 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 5F73761521 for ; Tue, 19 Jul 2022 00:10:21 +0000 (UTC) X-FDA: 79701917442.14.31CAE0F Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf01.hostedemail.com (Postfix) with ESMTP id CC7EA40062 for ; Tue, 19 Jul 2022 00:10:20 +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=1658189419; 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=sonD4+6h/lo8DkbhcKGrk86DBB0a/jVHQ/3znGtvMfA=; b=u99oHTV4VK/O3TDCdr5cCAEgrJ0jSsoO5ddoGvb111Gk6pLjAVWDvqrVzYNb7Wb/JyF6z6 HAZwpFa7j7U8ObOXHgsxkEZpgJ8X6wiOd0lmPxRowWlTEfUSAiRqIEO+4NVcziy0BwUP3O Sw7eRvUMkT3fiiNsPZFOuWOY/PN858I= 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 mm v2 01/33] kasan: check KASAN_NO_FREE_META in __kasan_metadata_size Date: Tue, 19 Jul 2022 02:09:41 +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=1658189421; a=rsa-sha256; cv=none; b=3jeDGefydCZPd7jo1WkeVTUYiykljLA0j/JTLBrdbTpe95MmBvA5SffFY9qF9vpJa2wO4Q QwKfn8LnaiwlOjYuejoX3A5Yqpuu2dveRTcfpL3C06S7MosGqQAERCmXa0l3hInTk63W6q 9cevsP8sogaxiKpJ4EVw4tYfeNGua4Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u99oHTV4; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 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=1658189421; 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=sonD4+6h/lo8DkbhcKGrk86DBB0a/jVHQ/3znGtvMfA=; b=ab6j+siz1BWOC8qYFIf7wcP0PseNITC+QdZEMD150ELjjQmYbGdtetq4TxQEJ3CLz3zZGU fyxE0D3p7Dxk+brt72Rdtvp3GDqtQ6yy9GkN+3b6IEZGX813bj9ybY1j5Wiwvwpf64N4C0 V1pCg631P+1o5GgGY6kkj3cTo6Ck30E= X-Rspamd-Queue-Id: CC7EA40062 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u99oHTV4; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: ffmkayyeh19bdwn6zudxi3eg3hteiujb X-HE-Tag: 1658189420-393813 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 707c3a527fcb..b7351b860abf 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,