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 36A91C433F5 for ; Mon, 14 Mar 2022 03:11:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5DBE6B0071; Sun, 13 Mar 2022 23:11:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0E458D0002; Sun, 13 Mar 2022 23:11:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ADF28D0001; Sun, 13 Mar 2022 23:11:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id 78DA56B0071 for ; Sun, 13 Mar 2022 23:11:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 18C0C8249980 for ; Mon, 14 Mar 2022 03:11:37 +0000 (UTC) X-FDA: 79241516634.26.AB87108 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf22.hostedemail.com (Postfix) with ESMTP id A21C4C001C for ; Mon, 14 Mar 2022 03:11:36 +0000 (UTC) Received: by mail-oi1-f174.google.com with SMTP id o83so8558901oif.0 for ; Sun, 13 Mar 2022 20:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=b97IRgdojmskoUj6xqTHzV6FHlt1zL1rWKMe4IXbzRY=; b=AQbTXJ84foDJZijT8rN9O+ZyaKxspYFHahatLu8HgjAPtx/RzWnyYpEt6luy35aGOD oLBFHv9ni+/8hOoFbjKWpsPx28eey7mnsCl8ArvINXwleTjqB3mM3vA5D1TNUXkqWliv R1fBtoUhRehEJ9HI9W0PQhHSCii56Kv7bFM5Zhu8Xzn54WbkcqrhSWUayTrCqiH4ISw5 07mlXsfA5SqIG9nVJB5Qsp14IxM7WTSBhquB7K2cjBJRrTToO//6Cj+kp627F4VcyDYF TYOaOcwpXt7TCRTiVqg+k4gcN4PHo8Z+KCddahoa2KEoClxiKPgiWc0grciteYzPicyX kgww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=b97IRgdojmskoUj6xqTHzV6FHlt1zL1rWKMe4IXbzRY=; b=oH49mIBeQ179XFz2vDnWjMxhC4fRysqiqznnl8/tydK6IZcvTH+EBy0h9XqKIPxN3Y TdwuK2zQPcU+Uqghp8PfiOKWDq5sugtKSjqrB9BcrufYBqw0OF6UDK+oRtcXsuZH9KO0 aK1JhaH6RwIga1Bx5/Qvgkd8zoAIrTTjvhYDh+veWyHIbjWa2Np3E3yragzeil44RORp qHXRbS0LacntX3HQYCDUSZx4ve0INh4B7g3rJ3scX8FgJggRXHXxNdNwoobV7DGfNmRh 8jsBm6vnq0mBvej8ypFWrhZSy90h4AUF8MYIyHlJLEtdp108j+yvC9V2R1mG5dqhQMdW 19Eg== X-Gm-Message-State: AOAM530/SVe6/Gu7ms90DvUKQhLPLb46jVo7jeuP/+k4RgwudGwnOBqG WH1betIJYnbnoauhzAJRFHxoHw== X-Google-Smtp-Source: ABdhPJyKEa+Se2UwgWD2hdDOZ7BJEdR1K3aXZDbCdRx68cKzGaePUH5fcZIQXDSUmEC6v67vWJ1SkA== X-Received: by 2002:a05:6808:8e4:b0:2ec:aea1:353a with SMTP id d4-20020a05680808e400b002ecaea1353amr6093082oic.27.1647227495871; Sun, 13 Mar 2022 20:11:35 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 60-20020a9d0642000000b005b22a82458csm6920561otn.55.2022.03.13.20.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Mar 2022 20:11:35 -0700 (PDT) Date: Sun, 13 Mar 2022 20:11:23 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Miaohe Lin cc: Hugh Dickins , akpm@linux-foundation.org, Herbert.van.den.Bergh@oracle.com, Alexey Gladkov , "Eric W. Biederman" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/mlock: fix potential imbalanced rlimit ucounts adjustment In-Reply-To: Message-ID: <1e758c8f-c87b-50ef-52db-942c8a86a32a@google.com> References: <20220310132417.41189-1-linmiaohe@huawei.com> <268b3146-2963-15b6-6d6-95a96853314@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A21C4C001C X-Stat-Signature: 1cfjdnzr85ytcd6eeiiug7tu7i5pgi8q Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AQbTXJ84; spf=pass (imf22.hostedemail.com: domain of hughd@google.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-HE-Tag: 1647227496-814971 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 Mon, 14 Mar 2022, Miaohe Lin wrote: > On 2022/3/14 10:40, Hugh Dickins wrote: > > On Thu, 10 Mar 2022, Miaohe Lin wrote: > > > >> user_shm_lock forgets to set allowed to 0 when get_ucounts fails. So > >> the later user_shm_unlock might do the extra dec_rlimit_ucounts. Fix > >> this by resetting allowed to 0. > >> > >> Fixes: 5ed44a401ddf ("do not limit locked memory when RLIMIT_MEMLOCK is RLIM_INFINITY") > >> Signed-off-by: Miaohe Lin > > > > NAK. user_shm_lock() remembers to declare "int allowed = 0" on entry. > > > > If lock_limit is RLIM_INFINITY, "allowed" will be set to 1. And if get_ucounts fails > in some corner cases, "allowed" will remain to be 1 while the user_shm_lock ops indeed > fails. Or am I miss something? You are right, I am wrong: sorry. Thanks for pointing now to that RLIM_INFINITY case. But then the Fixes tag is wrong: it should be Fixes: d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts") which introduced the possibility of error down there. With that, Acked-by: Hugh Dickins > > Many thanks for comment. > > >> --- > >> mm/mlock.c | 1 + > >> 1 file changed, 1 insertion(+) > >> > >> diff --git a/mm/mlock.c b/mm/mlock.c > >> index 29372c0eebe5..efd2dd2943de 100644 > >> --- a/mm/mlock.c > >> +++ b/mm/mlock.c > >> @@ -733,6 +733,7 @@ int user_shm_lock(size_t size, struct ucounts *ucounts) > >> } > >> if (!get_ucounts(ucounts)) { > >> dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked); > >> + allowed = 0; > >> goto out; > >> } > >> allowed = 1; > >> -- > >> 2.23.0