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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 30521C2B9F7 for ; Wed, 26 May 2021 10:48:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B3423613D8 for ; Wed, 26 May 2021 10:48:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3423613D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4605D6B0036; Wed, 26 May 2021 06:48:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 410346B006E; Wed, 26 May 2021 06:48:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B1B16B0070; Wed, 26 May 2021 06:48:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id F0D086B0036 for ; Wed, 26 May 2021 06:48:49 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9181D180AD820 for ; Wed, 26 May 2021 10:48:49 +0000 (UTC) X-FDA: 78183059178.01.7138851 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf27.hostedemail.com (Postfix) with ESMTP id 0985E8019122 for ; Wed, 26 May 2021 10:48:41 +0000 (UTC) Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) by smtp-out2.suse.de (Postfix) with ESMTP id DE0581FD29; Wed, 26 May 2021 10:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1622026127; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KbKOu0mEdoI8kb/j45kMc9SQNVujWd8DYO1qXhK9sJU=; b=eecEfF7/YaFpVcAsGAC8iuypEktd/q31uW5UstHTYrO+KI+9bc56yLBywjUGd33D8LMDME FtmYR41nzqhyTIp5StyyCIrjds3f5mkpYVvcOnj9nWFWH3bauf3T+FqXQXN/Qf2p82bNfK IDPJs96YXhFX9p2wUgtDZVyU+hD4JZA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1622026127; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KbKOu0mEdoI8kb/j45kMc9SQNVujWd8DYO1qXhK9sJU=; b=e03ko3PzoWQAGjlT5ZrE2L6sVje8ABvU+ugaDtkfvtUe43QjLEZUJcE0uvbOOLUwEHVBJW hRjijFPGMSrYtyCA== Received: from director2.suse.de (director2.suse-dmz.suse.de [192.168.254.72]) by imap.suse.de (Postfix) with ESMTPSA id C1F6A11A98; Wed, 26 May 2021 10:48:47 +0000 (UTC) Subject: Re: [PATCH v2 4/4] slub: Force on no_hash_pointers when slub_debug is enabled To: Stephen Boyd , Andrew Morton Cc: linux-kernel@vger.kernel.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , linux-mm@kvack.org, Petr Mladek , Joe Perches References: <20210526025625.601023-1-swboyd@chromium.org> <20210526025625.601023-5-swboyd@chromium.org> From: Vlastimil Babka Message-ID: <555eaf8b-deb2-fa49-ddef-a74645848159@suse.cz> Date: Wed, 26 May 2021 12:48:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210526025625.601023-5-swboyd@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 0985E8019122 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="eecEfF7/"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=e03ko3Pz; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam04 X-Stat-Signature: zaarsyfhe5im35u5rp4rk9sra9b6wr9c X-HE-Tag: 1622026121-885913 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 5/26/21 4:56 AM, Stephen Boyd wrote: > Obscuring the pointers that slub shows when debugging makes for some > confusing slub debug messages: > > Padding overwritten. 0x0000000079f0674a-0x000000000d4dce17 > > Those addresses are hashed for kernel security reasons. If we're trying > to be secure with slub_debug on the commandline we have some big > problems given that we dump whole chunks of kernel memory to the kernel > logs. Let's force on the no_hash_pointers commandline flag when > slub_debug is on the commandline. This makes slub debug messages more > meaningful and if by chance a kernel address is in some slub debug > object dump we will have a better chance of figuring out what went > wrong. > > Note that we don't use %px in the slub code because we want to reduce > the number of places that %px is used in the kernel. This also nicely > prints a big fat warning at kernel boot if slub_debug is on the > commandline so that we know that this kernel shouldn't be used on > production systems. > > Signed-off-by: Stephen Boyd > --- > > I opted for extern because I guess we don't want to advertise > no_hash_pointers_enable() in some sort of header file? It can be put in > a header file Hm looks like the bots disagree. I suppose a declaration right above definition in lib/vsprintf.c would silence them, but I'll leave it to printk maintainers if they would prefer that way or traditionally include/linux/kernel.h > but I see that the no_hash_pointers variable is also not > in a header file but exported as symbol. Yeah it's only used by tests, and a variable doesn't need separate declaration. > lib/vsprintf.c | 2 +- > mm/slub.c | 6 ++++++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index f0c35d9b65bf..cc281f5895f9 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -2186,7 +2186,7 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, > bool no_hash_pointers __ro_after_init; > EXPORT_SYMBOL_GPL(no_hash_pointers); > > -static int __init no_hash_pointers_enable(char *str) > +int __init no_hash_pointers_enable(char *str) > { > if (no_hash_pointers) > return 0; > diff --git a/mm/slub.c b/mm/slub.c > index bf4949115412..1c30436d3e6c 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -4451,6 +4451,8 @@ static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache) > return s; > } > > +extern int no_hash_pointers_enable(char *str); > + > void __init kmem_cache_init(void) > { > static __initdata struct kmem_cache boot_kmem_cache, > @@ -4470,6 +4472,10 @@ void __init kmem_cache_init(void) > for_each_node_state(node, N_NORMAL_MEMORY) > node_set(node, slab_nodes); > > + /* Print slub debugging pointers without hashing */ > + if (static_branch_unlikely(&slub_debug_enabled)) > + no_hash_pointers_enable(NULL); > + > create_boot_cache(kmem_cache_node, "kmem_cache_node", > sizeof(struct kmem_cache_node), SLAB_HWCACHE_ALIGN, 0, 0); > >