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=-18.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, URIBL_BLOCKED,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 2A755C432BE for ; Wed, 1 Sep 2021 08:58:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACFD160C3E for ; Wed, 1 Sep 2021 08:58:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ACFD160C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3BFAB6B006C; Wed, 1 Sep 2021 04:58:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36FCC6B0071; Wed, 1 Sep 2021 04:58:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 238296B0072; Wed, 1 Sep 2021 04:58:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 14D436B006C for ; Wed, 1 Sep 2021 04:58:27 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B66978249980 for ; Wed, 1 Sep 2021 08:58:26 +0000 (UTC) X-FDA: 78538403412.02.19A98E6 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf06.hostedemail.com (Postfix) with ESMTP id 2352B801A89C for ; Wed, 1 Sep 2021 08:58:25 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9C3D2224F7; Wed, 1 Sep 2021 08:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630486704; 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=XYk0l+EdwreY98ZhJQynz+aInvTJ1n/sBiNgZ6uBg9I=; b=dyQ2tadrZ364NOrfIoza+rII+plniVQnP7o5fg5O8ngtD1M4I0kczC4pc3uUI2Yf/Twlx3 f1f7rJUyN/6lWX2G+Oi4QUJYG4dwDhmoMINQ5Jtqu9FVOOQRRmzQ7JNBqAAdu0dEfWoVZU HCobDkoL/BH18ne/nkYHJYLQuZF6iTU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630486704; 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=XYk0l+EdwreY98ZhJQynz+aInvTJ1n/sBiNgZ6uBg9I=; b=Mp875vo8Z7xDqBoOjqlZoAsTuRd/uTGeGsMhX0AFffQrABujV/y5XYoZIAEhGSy5YamCW7 ttRw5DLuinrs60Aw== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 7E80F13A41; Wed, 1 Sep 2021 08:58:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id 7GeqHbBAL2E3EwAAGKfGzw (envelope-from ); Wed, 01 Sep 2021 08:58:24 +0000 Message-ID: <78d24243-9d92-43fd-92b5-17b88cc24314@suse.cz> Date: Wed, 1 Sep 2021 10:58:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Content-Language: en-US To: Imran Khan , geert@linux-m68k.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, "linux-mm@kvack.org" , Alexander Potapenko References: <20210901051914.971603-1-imran.f.khan@oracle.com> <20210901051914.971603-2-imran.f.khan@oracle.com> From: Vlastimil Babka Subject: Re: [RFC PATCH 1/2] lib, stackdepot: check stackdepot handle before accessing slabs. In-Reply-To: <20210901051914.971603-2-imran.f.khan@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=dyQ2tadr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Mp875vo8; spf=pass (imf06.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2352B801A89C X-Stat-Signature: wk9zcwpk7c7jayk6gnkrn1usge1w7p3h X-HE-Tag: 1630486705-214110 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: +CC linux-mm, Alex On 9/1/21 07:19, Imran Khan wrote: > stack_depot_save allocates slabs that will be used for storing > objects in future.If this slab allocation fails we may get to > a situation where space allocation for a new stack_record fails, > causing stack_depot_save to return 0 as handle. > If user of this handle ends up invoking stack_depot_fetch with > this handle value, current implementation of stack_depot_fetch > will end up using slab from wrong index. > To avoid this check handle value at the beginning. > Also issue a warning for nil handle values and when slab allocation > for stackdepot fails for the first time. > > Signed-off-by: Imran Khan > Suggested-by: Vlastimil Babka Agree but without the warnings please, especially the "stack depot handle is absent" one. It's just something that can happen e.g. in GFP_NOWAIT contexts and no need to spam dmesg. > --- > lib/stackdepot.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 0a2e417f83cb..1d42ef9ef766 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -232,6 +232,10 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, > struct stack_record *stack; > > *entries = NULL; > + if (!handle) { > + WARN(1, "stack depot handle is absent.\n"); > + return 0; > + } > if (parts.slabindex > depot_index) { > WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", > parts.slabindex, depot_index, handle); > @@ -303,6 +307,8 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, > page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER); > if (page) > prealloc = page_address(page); > + else > + WARN_ONCE(1, "slab allocation for stack depot failed.\n"); > } > > raw_spin_lock_irqsave(&depot_lock, flags); >