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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 254A7C04A68 for ; Thu, 28 Jul 2022 07:34:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 596E28E0001; Thu, 28 Jul 2022 03:34:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 545F16B0072; Thu, 28 Jul 2022 03:34:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40DA58E0001; Thu, 28 Jul 2022 03:34:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2D3716B0071 for ; Thu, 28 Jul 2022 03:34:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 02861AB6B1 for ; Thu, 28 Jul 2022 07:34:39 +0000 (UTC) X-FDA: 79735696320.11.A4CF429 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf04.hostedemail.com (Postfix) with ESMTP id 63B4A400B6 for ; Thu, 28 Jul 2022 07:34:38 +0000 (UTC) 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-out1.suse.de (Postfix) with ESMTPS id E922D33A20; Thu, 28 Jul 2022 07:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1658993676; 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=bNidsR0p1xyDX6IFAYEZX8Yv7vk0YXivGgQvV4ylVv0=; b=aaC4u3Suh3mW8YlM8QkRb+dD7I1g2nGJi8LnktSdTaJWvqILuCmO7vMAgeajPpWZDLpO6D uhsQIyiP5naW/fhD8JsHXjdsr4JdEUFZyJ9jr/Zr1qwQ9a7NWNpXJhih2drXMuQMATz2LP xEt1i9EmqspomOdb2HXeUlrQ+g1nsJA= 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 BEC9E13A7E; Thu, 28 Jul 2022 07:34:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vZWLLAw84mK+FgAAMHmgww (envelope-from ); Thu, 28 Jul 2022 07:34:36 +0000 Date: Thu, 28 Jul 2022 09:34:36 +0200 From: Michal Hocko To: =?utf-8?B?6ZSm5rGf5bGg?= Cc: Yang Shi , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [External] Re: [PATCH] vmscan: fix potential arbitrary pointer passed to kfree in unregister_shrinker Message-ID: References: <20220727090700.3238-1-tujinjiang@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658993678; a=rsa-sha256; cv=none; b=YF6tTVHTpGx3d7v74n2Stz9dqKGSwPV2zfc/iUVz5Ll2Lxmxg14Dxz5k7Al64QaM+2CfVI Xo4T28HdMI+ySPXU/UnxJ6u2ab2AQn8hojiVWAFwq6olm+DrulkUf1zyTHFWu45g+rWocb gtdQuGbzLi597G3SjDZLMhbPAtHVuF0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=aaC4u3Su; spf=pass (imf04.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658993678; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=bNidsR0p1xyDX6IFAYEZX8Yv7vk0YXivGgQvV4ylVv0=; b=2yaqseh7boFvYIeOK6jkqw/UgmGMMH5fziEXCCmegNQvDaAKZXxf4DbGHHPKf4c/2Oe2NL +lTW7AZQMiM13dWYCitn7gOoxWOv1wpdDDTfv+V6XduUjVGCgpQxvOkYrcEuJ8HUWh3awK uOFyj84SXqaKjXWKrZt9HDmWyJNDt9w= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=aaC4u3Su; spf=pass (imf04.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 63B4A400B6 X-Stat-Signature: fj71hudzt3s7nagr3iya3dzawntzrps6 X-HE-Tag: 1658993678-909940 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 Thu 28-07-22 10:37:26, 锦江屠 wrote: > On Wed, Jul 27, 2022 at 11:50 PM Yang Shi wrote: > > > > On Wed, Jul 27, 2022 at 7:43 AM Michal Hocko wrote: > > > > > > [Cc Yang Shi] > > > > Thanks, Michal. > > > > > On Wed 27-07-22 17:07:00, tujinjiang@bytedance.com wrote: > > > > From: Jinjiang Tu > > > > > > > > when shrinker is registered with SHRINKER_MEMCG_AWARE flag, > > > > register_shrinker will not initialize shrinker->nr_deferred, > > > > but the pointer will be passed to kfree in unregister_shrinker > > > > when the shrinker is unregistered. This leads to kernel crash > > > > when the shrinker object is dynamically allocated. > > > > > > Is this a real life problem? I thought shrinkers were pre-zeroed > > > already. Not that we should be relying on that but it would be good to > > > mention whether this is a code fortification or something that we should > > > be really worried about. > > > > Yes, all memcg aware shrinkers are actually pre-zeroed. The fs > > shrinkers (embedded in super_block) are allocated by kzalloc, all > > other shrinkers are static declared. So I don't think it will cause > > any crash in real life. > > > > Yes, the shrinkers in the current kernel will not cause crash, but a new > memcg aware shrinker may be added in the future, and I think we > should not assume the shrinker is pre-zeroed. Agreed. Especially when that is not documented anywhere. > Function free_prealloced_shrinker does not assume the shrinker is pre-zeroed, > and does not call kfree(shrinker->nr_deferred) if the shrinker is memcg aware. > So I think it is better for unregister_shrinker to call kfree only > when the shrinker > is not memcg aware. It would be really great to mention this intention in the changelog. Your initial wording might make an impression this is a fix for an existing problem. > > > > To fix it, this patch initialize shrinker->nr_deferred at the > > > > beginning of prealloc_shrinker. > > > > > > It would be great to add > > > Fixes: 476b30a0949a ("mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers") Do not use Fixes tag as this is not a real problem currently. -- Michal Hocko SUSE Labs