From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 5A330C433E0 for ; Wed, 17 Jun 2020 17:49:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1C62E21655 for ; Wed, 17 Jun 2020 17:49:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BAu0Qdvr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C62E21655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7FFC96B0005; Wed, 17 Jun 2020 13:49:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B12D6B0007; Wed, 17 Jun 2020 13:49:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69E996B0008; Wed, 17 Jun 2020 13:49:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 53F956B0005 for ; Wed, 17 Jun 2020 13:49:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DDE70180ACEF3 for ; Wed, 17 Jun 2020 17:49:32 +0000 (UTC) X-FDA: 76939440984.24.toes43_231363826e09 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id C13B5299C7 for ; Wed, 17 Jun 2020 17:49:32 +0000 (UTC) X-HE-Tag: toes43_231363826e09 X-Filterd-Recvd-Size: 5391 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Wed, 17 Jun 2020 17:49:32 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id v24so1273715plo.6 for ; Wed, 17 Jun 2020 10:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=V8lfggKruB1yxFCmUN4ar1a8ljPH48vbHQvDBnle06w=; b=BAu0QdvrHfiQZ08QWi34W+w11gyEywFYCO6sOb3qBaVIoncA8HDODvGWklons9V1Bt 9lyak1FCWvUwiO4WdJ4oM+LCoWrMcSKhhzVa1IfTr4IpRgUKuExeRgmEwAsXm+ae8C90 uYBs4m556VRNtgXQtGduEa4erGq/5rIbRdayM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=V8lfggKruB1yxFCmUN4ar1a8ljPH48vbHQvDBnle06w=; b=LgzPuAY6uLzo4Et4CdYm0c05GViCj9D0ilOAfO2dVnaXeFwdSArI6cc2GfpJhNR6P3 iAtY67cLy8TYyWiWvjMZ7IdCFwPysluSnPur2kp/Z07Ut3X1qawt3E54Zi0INMO1rjfP /kXRfpMM5G0XUlX98iUgWvpQYy/CmCR7uiCIBVM7l2+SGiipHqDYJr/e/AxZG6+Y4Px+ D6A2wmyV7YdJ3M2zPpa+FNGHvFTRvIcLllf7RNstK3x89jNZx4xcVScoQyROrXIl3dv/ hQjUMESmaDvvDXWLGNZXqYZkJ9iatTM4hCDdn4J9mBKLMdy0ZkYx8HDeypMQtU5y9FBn weUQ== X-Gm-Message-State: AOAM531bQ2ItiyKN8pMLgjpTI9dfy9Sm8lfPnc6VpnemE50ILKhJ6Xcj vQEvH+Z7nt4Aksv1gHKJ581oww== X-Google-Smtp-Source: ABdhPJw9S4YN836QBe6/J0KFILnonDrNZ5QstUwSC3O98xpTSz+s1IeX7ybnbluBUeCNZ5SSyIApIQ== X-Received: by 2002:a17:90b:3c6:: with SMTP id go6mr219283pjb.224.1592416171161; Wed, 17 Jun 2020 10:49:31 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mu17sm213065pjb.53.2020.06.17.10.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 10:49:30 -0700 (PDT) Date: Wed, 17 Jun 2020 10:49:29 -0700 From: Kees Cook To: Vlastimil Babka Cc: Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vinmenon@codeaurora.org, Matthew Garrett , Roman Gushchin , Jann Horn , Vijayanand Jitta Subject: Re: [PATCH 9/9] mm, slab/slub: move and improve cache_from_obj() Message-ID: <202006171039.FBDF2D7F4A@keescook> References: <20200610163135.17364-1-vbabka@suse.cz> <20200610163135.17364-10-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200610163135.17364-10-vbabka@suse.cz> X-Rspamd-Queue-Id: C13B5299C7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: On Wed, Jun 10, 2020 at 06:31:35PM +0200, Vlastimil Babka wrote: > The function cache_from_obj() was added by commit b9ce5ef49f00 ("sl[au]b: > always get the cache from its page in kmem_cache_free()") to support kmemcg, > where per-memcg cache can be different from the root one, so we can't use > the kmem_cache pointer given to kmem_cache_free(). > > Prior to that commit, SLUB already had debugging check+warning that could be > enabled to compare the given kmem_cache pointer to one referenced by the slab > page where the object-to-be-freed resides. This check was moved to > cache_from_obj(). Later the check was also enabled for SLAB_FREELIST_HARDENED > configs by commit 598a0717a816 ("mm/slab: validate cache membership under > freelist hardening"). > > These checks and warnings can be useful especially for the debugging, which can > be improved. Commit 598a0717a816 changed the pr_err() with WARN_ON_ONCE() to > WARN_ONCE() so only the first hit is now reported, others are silent. This > patch changes it to WARN() so that all errors are reported. > > It's also useful to print SLUB allocation/free tracking info for the offending > object, if tracking is enabled. We could export the SLUB print_tracking() > function and provide an empty one for SLAB, or realize that both the debugging > and hardening cases in cache_from_obj() are only supported by SLUB anyway. So > this patch moves cache_from_obj() from slab.h to separate instances in slab.c > and slub.c, where the SLAB version only does the kmemcg lookup and even could Oops. I made a mistake when I applied CONFIG_SLAB_FREELIST_HARDENED here, I was thinking of SLAB_FREELIST_RANDOM's coverage (SLUB and SLAB), and I see now that I never updated CONFIG_SLAB_FREELIST_HARDENED to cover SLAB and SLOB. The point being: I still want the sanity check for the SLAB case under hardening. This needs to stay a common function. The whole point is to catch corruption from the wrong kmem_cache * being associated with an object, and that's agnostic of slab/slub/slob. So, I'll send a follow-up to this patch to actually do what I had originally intended for 598a0717a816 ("mm/slab: validate cache membership under freelist hardening"), which wasn't intended to be SLUB-specific. -- Kees Cook