Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3559614rwb; Mon, 5 Sep 2022 14:08:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR7phFUYqejILYtBYHkLRhfSM/Y5NYtb8/ucWb+y3L+xBArgPF+zK6zA3fJOT9PkG/JSu9l2 X-Received: by 2002:a50:a69d:0:b0:44e:bf40:395f with SMTP id e29-20020a50a69d000000b0044ebf40395fmr1444630edc.234.1662412122896; Mon, 05 Sep 2022 14:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662412122; cv=none; d=google.com; s=arc-20160816; b=btjU+cse/4wEmGlDkZ42OwhSbDYqj+RqMookieAz3Je+iou1aJd2AhullL2QG4037W Eiwd98iQd1jHBoEX64G11iZQP2yLQpc6TFCRhguzWAIHYh9uQxmu8cU86a/vNDncfxKS yHeZRTMU8zzMEATLbk/WXvmKA+X8VmxNq77BN8JvLLvbIg9/XTkkbTeV3gqOIxW8AQ6m 7O4pvYYa4uQLV6Y4LAShKrpGkUH14cCX9aIo56bA0mjWOWpD5PAh8VUvqxBSm8mxkBCv thCddVA9pr+ijYm9WZWc3brKX0ZQOZsdkxWxTZ+9yxgiOmx5gsLj0UZY1XfQH93K1nJ7 LHdw== 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=VgD6aAPrK9DNDeYC6eoXfhD6gN4R30dJg8cA4lzePd8=; b=rC31Wft8JJ73UWXd2VXCY+LYS6PRPA3e+C2RHB8mehM1Qs6PKl9fbBfcbdchwHDrQr o5WFhuVgzbDIu0ERO1Qp6NfqtasyQDbMjurLIYA9wbzqqAj4tj1UlR6tdgr5avqIOJFK a/remfqi51TT+gbLUdsK2oDYJ/vW9Zc4jcJikyTHibN0wy3V5CyTCEE8lQS+JO1udEjU NRRc6QrRq7W12Upq99f3OEJTpfSxFxO8XnTO2DS/WkUpXZwg6dyVmH0HyXxzZHKEVTvW XfTQWHJc54/qDoSjn3YsAl0zyOS2fTaBMQVk7T0/81dWEevIya/zosaTrI4CZxSij0ve N4Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RxlSmPaR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg2-20020a1709072cc200b0073d7ba692b3si8321684ejc.375.2022.09.05.14.08.16; Mon, 05 Sep 2022 14:08:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RxlSmPaR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232037AbiIEVF5 (ORCPT + 99 others); Mon, 5 Sep 2022 17:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiIEVF4 (ORCPT ); Mon, 5 Sep 2022 17:05:56 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79FEF5925D for ; Mon, 5 Sep 2022 14:05:55 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.25.1