Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1649623pxp; Thu, 10 Mar 2022 09:21:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0UYBxuhJ7STpi2W90j/UXJJjfOfAfmtIvRDghADkKj6/OF7yknVAqRWHFPm3JVK49J9Y1 X-Received: by 2002:a05:6870:79d:b0:da:56e3:fe99 with SMTP id en29-20020a056870079d00b000da56e3fe99mr3335870oab.95.1646932861032; Thu, 10 Mar 2022 09:21:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646932861; cv=none; d=google.com; s=arc-20160816; b=DNIjHNyffei27iXVomIfjVENQpfX2pYyVGa1OVW4AlEnbaM5vkJ+TGb1Q7Ef2om5Wj SDXnMSRNnPxN57ElPEGqh5+sHORzSSqOnf0ATq/9PekexWDfkJTYwNgkry3gSul7CAoa pUBID+XCYWnOgxicmpd97cdWUg3EoL5eOcPbUP7TSKmtO5QpsU7tGDxZ5XEY5zA5+MYh SESoKNC631t9dk/kz2yjAMezx36lKhAFYmQ/2hFhOzuVVVWHhTSixJSE+tU9kpgXeTsV cpzU7eaVhfCEbrih/IPtKhzzkYmsK3OeJpqjIdKolzOcyTtLCIuUjVnGVSvYvxl1/cv4 0+og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=aPViugEgoTQ/TLoAy25jS94Y29t9yqb+HJ1EHnZOgcw=; b=rc0XKGoXk9qiDlNYzUxBU9jeauNMUZzPmU45JcI1bqT5Mk6pl5shNWFswNSUgSUefV dVgbJSGx9/jJ4z4h7MK2okGxiDJOicCr5SINYxNA86cyIZtC2pOSYnlCUI1l+GerJl+Y wvX3vkUjU6kBwkO8wNM5rhW8DHrwUEID3IGdaC8gkBnENtN0Oq1LYHERpDiLiA335cIe fzoOUtpn3nf0ncK9l0S3sw0xY8OdyWMfiVqE8Y4eSOaOke3m3HOGPGkZCsvh8xaMVL4p 9je2sDDm2GgDqFpiaKkXG8c6TMWd5rheuHj5cmHggPpJLzUYkc6o7YTx2HjgK5y7aN5/ Vd/g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r22-20020a056830081600b005b23700a490si3880811ots.19.2022.03.10.09.20.44; Thu, 10 Mar 2022 09:21:01 -0800 (PST) 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; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242394AbiCJN0N (ORCPT + 99 others); Thu, 10 Mar 2022 08:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238415AbiCJN0M (ORCPT ); Thu, 10 Mar 2022 08:26:12 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA8E914D275 for ; Thu, 10 Mar 2022 05:25:08 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KDqWz6Bjpzdb7R; Thu, 10 Mar 2022 21:23:43 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 10 Mar 2022 21:25:06 +0800 From: Miaohe Lin To: CC: , , , , Subject: [PATCH] mm/mlock: fix potential imbalanced rlimit ucounts adjustment Date: Thu, 10 Mar 2022 21:24:17 +0800 Message-ID: <20220310132417.41189-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 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 --- 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