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 99FC3C433F5 for ; Tue, 22 Mar 2022 08:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 175146B0072; Tue, 22 Mar 2022 04:08:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 126086B0073; Tue, 22 Mar 2022 04:08:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 013CE6B0074; Tue, 22 Mar 2022 04:08:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id E9EA46B0072 for ; Tue, 22 Mar 2022 04:08:10 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A2502215FE for ; Tue, 22 Mar 2022 08:08:10 +0000 (UTC) X-FDA: 79271294340.13.FC2F247 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf24.hostedemail.com (Postfix) with ESMTP id 169E5180026 for ; Tue, 22 Mar 2022 08:08:09 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id C2754210F4; Tue, 22 Mar 2022 08:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1647936488; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vWWBrjD2pp3iNhrZ3GjqkzMZLE0dgi1nHcO9ba8+iIE=; b=GvUc0kQMo2NdirWOqVSKgpGkOiXIweWRuC7GBCQxEN65SaZ/S4HQdEtw+DtAZU5iAch+Ng sXbtpsOuF1g1hMRUrVIUtzFHmDwj9qEynVMYpT6g9oypKTSFfeF84QFd6nnUuLqKyN0MUv rbV1JSJDk+FAFkTh0fRM7lVsR0l51ZY= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A7F47A3B98; Tue, 22 Mar 2022 08:08:08 +0000 (UTC) Date: Tue, 22 Mar 2022 09:08:08 +0100 From: Michal Hocko To: Miaohe Lin Cc: akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, mgorman@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/mempolicy: fix mpol_new leak in shared_policy_replace Message-ID: References: <20220322083456.16563-1-linmiaohe@huawei.com> <8c7d2ef2-08d7-ea50-a82b-9e9800c5f54c@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8c7d2ef2-08d7-ea50-a82b-9e9800c5f54c@huawei.com> Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=GvUc0kQM; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf24.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 169E5180026 X-Stat-Signature: 74ugcxp65kjna1g4sp3ypqqs8zatysa3 X-HE-Tag: 1647936489-265264 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 Tue 22-03-22 09:50:35, Miaohe Lin wrote: > On 2022/3/21 20:12, Michal Hocko wrote: > > On Tue 22-03-22 16:34:56, Miaohe Lin wrote: > >> If mpol_new is allocated but not used in restart loop, mpol_new will be > >> freed via mpol_put before returning to the caller. But refcnt is not > >> initialized yet, so mpol_put could not do the right things and might leak > >> the unused mpol_new. > > > > I would just add: > > > > This would happen if mempolicy was updated on the shared shmem file > > while the sp->lock has been dropped during the memory allocation. > > > > Do you mean the below commit log? > > """ > If mpol_new is allocated but not used in restart loop, mpol_new will be > freed via mpol_put before returning to the caller. But refcnt is not > initialized yet, so mpol_put could not do the right things and might leak > the unused mpol_new. This would happen if mempolicy was updated on the > shared shmem file while the sp->lock has been dropped during the memory > allocation. > > This issue could be triggered easily with the below code snippet if > there're many processes doing the below work at the same time: > > shmid = shmget((key_t)5566, 1024 * PAGE_SIZE, 0666|IPC_CREAT); > shm = shmat(shmid, 0, 0); > loop many times { > mbind(shm, 1024 * PAGE_SIZE, MPOL_LOCAL, mask, maxnode, 0); > mbind(shm + 128 * PAGE_SIZE, 128 * PAGE_SIZE, MPOL_DEFAULT, mask, > maxnode, 0); > } > """ Yes, LGTM. Thanks! -- Michal Hocko SUSE Labs