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=-19.5 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 16DEDC432BE for ; Thu, 2 Sep 2021 07:53:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 87D8B610C9 for ; Thu, 2 Sep 2021 07:53:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87D8B610C9 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 04D7F8D0002; Thu, 2 Sep 2021 03:53:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F18C68D0001; Thu, 2 Sep 2021 03:53:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D91DB8D0002; Thu, 2 Sep 2021 03:53:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id C6AB18D0001 for ; Thu, 2 Sep 2021 03:53:51 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 805FE22AAB for ; Thu, 2 Sep 2021 07:53:51 +0000 (UTC) X-FDA: 78541869462.04.5003B82 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf29.hostedemail.com (Postfix) with ESMTP id 0E0E19000249 for ; Thu, 2 Sep 2021 07:53:50 +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 816F822473; Thu, 2 Sep 2021 07:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630569229; 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=7xvu8P4rCUE+QdeioS9zYqea657adsGu4aiuscbEHhA=; b=IRZvobgjzVw6AarWxep/eqwiKcJEyTXxc1dn93G6A5YLaxx62CBuVqt5aD+Ra7BmTpsmgx p7H2gJZB88EBWP+h+rnR9ahRaCH/cJppapa4VBqm0dw9MurdOZ0GvzPJQJshDpbLRu9nUB adP2KHbtYYKyGavlx4gRGkEJEVva9lk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630569229; 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=7xvu8P4rCUE+QdeioS9zYqea657adsGu4aiuscbEHhA=; b=kDaxr228qJM3i8FMa9Gf7sXtF3aEX8NCx1v1s8f+2rgFyiGPCL32dRJwWP/BndbMk83qm6 73dLqv5lHEMf2tCA== 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 5199C1389C; Thu, 2 Sep 2021 07:53:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id OrOFEg2DMGFlQAAAGKfGzw (envelope-from ); Thu, 02 Sep 2021 07:53:49 +0000 Message-ID: Date: Thu, 2 Sep 2021 09:53:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: Re: [RFC PATCH v2 1/2] lib, stackdepot: check stackdepot handle before accessing slabs. Content-Language: en-US To: Imran Khan , geert@linux-m68k.org, akpm@linux-foundation.org, ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210902000154.1096484-1-imran.f.khan@oracle.com> <20210902000154.1096484-2-imran.f.khan@oracle.com> From: Vlastimil Babka In-Reply-To: <20210902000154.1096484-2-imran.f.khan@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 0E0E19000249 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IRZvobgj; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kDaxr228; dmarc=none; spf=pass (imf29.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam01 X-Stat-Signature: njise19yu593fuyrhsow3n96o4ybec8e X-HE-Tag: 1630569230-864972 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 9/2/21 02:01, 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. > > Signed-off-by: Imran Khan > Suggested-by: Vlastimil Babka Acked-by: Vlastimil Babka > --- > lib/stackdepot.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 0a2e417f83cb..67439c082490 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -232,6 +232,9 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, > struct stack_record *stack; > > *entries = NULL; > + if (!handle) > + 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); >