From patchwork Thu Mar 4 20:52:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12116787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92CA0C433DB for ; Thu, 4 Mar 2021 20:53:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03AC764F23 for ; Thu, 4 Mar 2021 20:53:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03AC764F23 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 132AF6B0005; Thu, 4 Mar 2021 15:53:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E3EA6B0006; Thu, 4 Mar 2021 15:53:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA1196B0007; Thu, 4 Mar 2021 15:53:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id CA1066B0005 for ; Thu, 4 Mar 2021 15:53:02 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 918BF18016C90 for ; Thu, 4 Mar 2021 20:53:02 +0000 (UTC) X-FDA: 77883391404.15.603AAF7 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf23.hostedemail.com (Postfix) with ESMTP id 97D9EA0000FF for ; Thu, 4 Mar 2021 20:53:01 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id w10so3035710wmk.1 for ; Thu, 04 Mar 2021 12:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=4CjcEvJ61GkUIoAFgSTKRu5Tq1H6wn08RVLBK2Lt0I0=; b=kQcOCQ/cMB/X2WRSuwsg8LBq8X+nEul9d6IKcKn7tPT4uxnd5PINYXXdeMrZdAE3Ej zqbHl++wLZTRVvYlU6lwOasPy3DOcMt0FVu+/aCX6o2vfuEpE1DFuOUHZh4FoD0sx7MW dgZQizaqek8333Yq8IIeacWBNyot8v6B/FdhLhlW8Aju/OFuVbxcPdSIkysxPYTK6KdC ceAmKMO0lt/2+V3pFnTKJRcKZRgFbg0XO5rCQKb8OkxZRW2o/I0qYJnCezuIQiYNe3dz 6xinkRvy1YAnPfeZjNGHpn2UaEQw67OZisxF6BqziY46z7vtzn27GihW4JeIN601IeB+ jtAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=4CjcEvJ61GkUIoAFgSTKRu5Tq1H6wn08RVLBK2Lt0I0=; b=czN9gioENgoVrR7Vwm9GDodHRJFhUo3GlIfMbBH+Wj3GrSGqIYgVS03A+4EuZBdsLK FXZnMLJRF5PpaBUn7L4mWikRi8fwTU5/bP+LkLkQ82Qezh0yJIcWCW4y+AkQy/eTmrN7 BZz0ViykaWijFLFRTGKpcXKowlWkF8snxtAGmImtZ3p4KSKpSdw0HOVgM1RJ/wAKVI7L doFDGMDdV9XcE8j/hx/jb++VMDlxUKss1RWmZ+9pEuCR56qPI97pVi9lfveQ3INOsD/a 6HEfmDiNLVonSow0bYBUbthsbWRiVlK5FfGzbKH7566MUxeSELXKKvUs9y5dxDzjF7Ds wD2Q== X-Gm-Message-State: AOAM532a4P18Nn5Iwmx0mpHltqsDlDwz7Ot7WjV51IhmavWMvHLnFbYk 5lt6cCsNbH6xz9kNPEqP63tjFz76jQ== X-Google-Smtp-Source: ABdhPJx7HwfiRm3Q+u5arI/IWcJ3KLG5rJXKgeoYlpazKcjtB/gExGHlBdBa1ZrXsLoc4m0JMTrmb82jKg== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:adef:40fb:49ed:5ab6]) (user=elver job=sendgmr) by 2002:a7b:c18e:: with SMTP id y14mr1459027wmi.1.1614891179563; Thu, 04 Mar 2021 12:52:59 -0800 (PST) Date: Thu, 4 Mar 2021 21:52:56 +0100 Message-Id: <20210304205256.2162309-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH mm] kfence, slab: fix cache_alloc_debugcheck_after() for bulk allocations From: Marco Elver To: elver@google.com, akpm@linux-foundation.org Cc: glider@google.com, dvyukov@google.com, andreyknvl@google.com, jannh@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com X-Stat-Signature: 8yw4du5zsqgq7h1nuhmsf9gj79ea9hsu X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 97D9EA0000FF Received-SPF: none (flex--elver.bounces.google.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from="<3q0hBYAUKCEoqx7q3s00sxq.o0yxuz69-yyw7mow.03s@flex--elver.bounces.google.com>"; helo=mail-wm1-f74.google.com; client-ip=209.85.128.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614891181-892799 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: cache_alloc_debugcheck_after() performs checks on an object, including adjusting the returned pointer. None of this should apply to KFENCE objects. While for non-bulk allocations, the checks are skipped when we allocate via KFENCE, for bulk allocations cache_alloc_debugcheck_after() is called via cache_alloc_debugcheck_after_bulk(). Fix it by skipping cache_alloc_debugcheck_after() for KFENCE objects. Signed-off-by: Marco Elver --- mm/slab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab.c b/mm/slab.c index 51fd424e0d6d..ae651bf540b7 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2992,7 +2992,7 @@ static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep, gfp_t flags, void *objp, unsigned long caller) { WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO)); - if (!objp) + if (!objp || is_kfence_address(objp)) return objp; if (cachep->flags & SLAB_POISON) { check_poison_obj(cachep, objp);