From patchwork Tue Mar 22 21:44:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12789211 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 11848C433EF for ; Tue, 22 Mar 2022 21:45:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A63B6B0122; Tue, 22 Mar 2022 17:45:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 955A86B0123; Tue, 22 Mar 2022 17:45:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81E156B0124; Tue, 22 Mar 2022 17:45:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 706EA6B0122 for ; Tue, 22 Mar 2022 17:45:00 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 468FB23F88 for ; Tue, 22 Mar 2022 21:45:00 +0000 (UTC) X-FDA: 79273352760.08.B0494AB Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf14.hostedemail.com (Postfix) with ESMTP id 62FE710002F for ; Tue, 22 Mar 2022 21:44:59 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ADFFDB81DB9; Tue, 22 Mar 2022 21:44:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65988C340EC; Tue, 22 Mar 2022 21:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647985497; bh=xpb+C+JgfC5R4O8FqnsK5U6W1BFO1h90Du/JBYTules=; h=Date:To:From:In-Reply-To:Subject:From; b=RiFbCSUvOoTtpC/WBF8XprLOMs01Q5mjp8Rlx7EuMaXF2/rTq+WJaAHAT4pxbHSJA fqinLT2WCaMWNkx2E26MQFTE3qNaDVPtl7ykLhmwQPGrXbayUcS15yqA82TIhMba2j b9WWFRaYNnfMutq/K0F0dYXU9Rv9PJPQ9BKdJQwM= Date: Tue, 22 Mar 2022 14:44:56 -0700 To: hughd@google.com,herbert.van.den.bergh@oracle.com,chris.mason@oracle.com,linmiaohe@huawei.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220322143803.04a5e59a07e48284f196a2f9@linux-foundation.org> Subject: [patch 127/227] mm/mlock: fix potential imbalanced rlimit ucounts adjustment Message-Id: <20220322214457.65988C340EC@smtp.kernel.org> X-Stat-Signature: bujh49u4hu31xyubdrdag4zo3uh7jiee Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=RiFbCSUv; spf=pass (imf14.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 62FE710002F X-HE-Tag: 1647985499-873527 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: From: Miaohe Lin Subject: mm/mlock: fix potential imbalanced rlimit ucounts adjustment 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. Link: https://lkml.kernel.org/r/20220310132417.41189-1-linmiaohe@huawei.com Fixes: d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts") Signed-off-by: Miaohe Lin Reviewed-by: Andrew Morton Acked-by: Hugh Dickins Cc: Herbert van den Bergh Cc: Chris Mason Signed-off-by: Andrew Morton --- mm/mlock.c | 1 + 1 file changed, 1 insertion(+) --- a/mm/mlock.c~mm-mlock-fix-potential-imbalanced-rlimit-ucounts-adjustment +++ a/mm/mlock.c @@ -839,6 +839,7 @@ int user_shm_lock(size_t size, struct uc } if (!get_ucounts(ucounts)) { dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked); + allowed = 0; goto out; } allowed = 1;