Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3891952rwa; Tue, 23 Aug 2022 12:01:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR6wxzmghjVc0FvsK0ehIqDejOPNMylcnN3DJTcElIO+lfXMGgXkziTo7YKN8GeMI8vkBJay X-Received: by 2002:a63:2110:0:b0:41d:234f:16aa with SMTP id h16-20020a632110000000b0041d234f16aamr21229846pgh.481.1661281278704; Tue, 23 Aug 2022 12:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661281278; cv=none; d=google.com; s=arc-20160816; b=alM4BPW4IB5BSl7oaL68XCKSZrvekXMwVqBwdlvkTsq5g8hT8YCYX1zKRJoXrb6N4t 2qNzV2krXnzLwbHDimkYCNYqZGv5cUUnG5Tugkux5mjy4qISbzTBqZmP4TnmMe0dFqeZ h7dBAAxoPUJs3HhPSNr0MH8DgJpHvbRkYAoSs2HpDsTOrebjRVoKzXfajn9EBBrzN1ij g2z0EACFghDJa0dixksglqX0foYJeH01OXaetyvAT5I3Zhgm0pvzDk7vOevEX3viWxr7 GB7emDBKqidfwHOYE5ZxsZ3JQFR6BFK50AeuiE+SLK0dlPNaOfnWKq9urbCFe6xUTPyg R/FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=swl0ArwDJ9fYdGl9+sc2cIn33V7qnlspcwq64fzCXA4=; b=u7d0+Q4Yq6cDFeHH0OumsRT0Mg4wWSZN1st8mZ6cNALsl5TKRHyl/TbvYccjq5RF4I hzosTMm/o8mZkH2MeqhmN8S8/fXHtjj+RramreicFLt5ZUxXELBcmtg6+0hmahv0my1A SH6njT+YyyEJVX/LeCuKrM72PMEmSTkVRzUch/uTQewYvAb7OlsU5tfd51Atp9r13zE6 k1EmrkM5he4hes1wWD8taeVec6DHeo7ZFnENphW28pSPGGoTBIxx+2lMbUUlRmlvmbhR aHIicPPe+Ye7PpiNZAJuQXNpI9NC6LGE2Ul7l8uBiPisq/cqG4UhsRc/AVQUkSaoNYhw aLzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dZBF3VTS; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 16-20020a630310000000b004296709deaesi13475978pgd.291.2022.08.23.12.01.06; Tue, 23 Aug 2022 12:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dZBF3VTS; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbiHWReP (ORCPT + 99 others); Tue, 23 Aug 2022 13:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232404AbiHWRdN (ORCPT ); Tue, 23 Aug 2022 13:33:13 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20BEA72FC0 for ; Tue, 23 Aug 2022 08:12:03 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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-out2.suse.de (Postfix) with ESMTPS id C13811F8C0; Tue, 23 Aug 2022 15:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1661267521; 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=swl0ArwDJ9fYdGl9+sc2cIn33V7qnlspcwq64fzCXA4=; b=dZBF3VTSSiCBUwQ7srJtI4g56FuCHLt9c0BREgY+JUIqQpRGoPb4NZJpICbulz0m25lA0D 8BJM4N8BQlgIav4zdMz8kknukd3Y6BRtrks+J7AdxKzgMZsAxx6bokpALMXF6eA3znXHOw iYvUnwMo7RAogjslO/VZf6WjOPZEJxs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1661267521; 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=swl0ArwDJ9fYdGl9+sc2cIn33V7qnlspcwq64fzCXA4=; b=b14Y4p1UIoZYqGPFtWZ1sDYjp//mkgulkjKpJqcY92E0Izppe/Dx1wGK3VNFLg9cy4jgHT g4euHe2F1fAWC6AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8AC9F13A89; Tue, 23 Aug 2022 15:12:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iQqwIEHuBGMjFgAAMHmgww (envelope-from ); Tue, 23 Aug 2022 15:12:01 +0000 Message-ID: <66e25026-a86a-0157-3671-cf66eb53964c@suse.cz> Date: Tue, 23 Aug 2022 17:12:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH v4 17/17] mm/sl[au]b: check if large object is valid in __ksize() Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marco Elver References: <20220817101826.236819-1-42.hyeyoo@gmail.com> <20220817101826.236819-18-42.hyeyoo@gmail.com> From: Vlastimil Babka In-Reply-To: <20220817101826.236819-18-42.hyeyoo@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/17/22 12:18, Hyeonggon Yoo wrote: > If address of large object is not beginning of folio or size of > the folio is too small, it must be invalid. BUG() in such cases. > > Cc: Marco Elver > Suggested-by: Vlastimil Babka > Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > Reviewed-by: Vlastimil Babka > --- > mm/slab_common.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 9c273a5fb0d7..98d029212682 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -984,8 +984,11 @@ size_t __ksize(const void *object) > > folio = virt_to_folio(object); > > - if (unlikely(!folio_test_slab(folio))) > + if (unlikely(!folio_test_slab(folio))) { > + BUG_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE); > + BUG_ON(object != folio_address(folio)); > return folio_size(folio); > + } > > return slab_ksize(folio_slab(folio)->slab_cache); > } In light of latest Linus' rant on BUG_ON() [1] I'm changing it to WARN_ON and return 0, as it was in v3. [1] https://lore.kernel.org/all/CAHk-=wiEAH+ojSpAgx_Ep=NKPWHU8AdO3V56BXcCsU97oYJ1EA@mail.gmail.com/ diff --git a/mm/slab_common.c b/mm/slab_common.c index 98d029212682..a80c3a5e194d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -985,8 +985,10 @@ size_t __ksize(const void *object) folio = virt_to_folio(object); if (unlikely(!folio_test_slab(folio))) { - BUG_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE); - BUG_ON(object != folio_address(folio)); + if (WARN_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE)) + return 0; + if (WARN_ON(object != folio_address(folio))) + return 0; return folio_size(folio); }