Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1761376pxb; Sun, 10 Jan 2021 09:46:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnsDzeeMa/FizzrYld4+ZI7a1jZ5kD/jIyPJXkZmf+3imaSR50pdcV3btpHnMXCNCZkdOA X-Received: by 2002:a17:906:408f:: with SMTP id u15mr8685913ejj.84.1610300799267; Sun, 10 Jan 2021 09:46:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610300799; cv=none; d=google.com; s=arc-20160816; b=D3cHeJEK0F2EqxM7bx5fb3iR6hefG4iZF04qLbAmGcx9ecziqlyJ6I5Kl3NAx+5sUS Hm2OfGNMwqz6J97mGS+IdyeZQ8gEIg9jwX3o4r3KhDmQh+Ut+Fc+wdMgcAwv3d5N3eoU QPgUOHjRUw/1N+v72M2vpRUVdN5kT8D2aU3toL1KzA8fuyPpK7JuJF79qiut1k1wVs+z elEOsNubdcPDMCQxZLQ25Q5PIPXCbTPiAGmq6YoxqNqQ2TUn03YD9+uPMEMZfq21irJe GkaFMW+6hkYyczAB6E7LzkWAuIhPyXQeRguDl5ha6JCVBzr+uPnXgiOr3dCVnIQyQXFH mjGQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=B2QB/OM9UF0KPILCY7BopllXbI1yeCn8ByhCsPg2Rz4=; b=CYjRZjfJK4gm8OM/8tD2CKIJQxBHjhMsqKU+/KPZL74SaxtmbJsafruV2OGldxLj0+ jG8YQfo8tWkZNcoVWiccnOdUDZAV5BgWAtZWxmXgQQAVpAjyFtN9Dx1EmGDRIc2li5YH G67ErnpuyphJskR3Axzd7Aufqk6rPmtNyqoP6cOZQ88t/uXww0S5Gq+duDLOsSn60tWl 6xbL+JFl3csFxy85IUIV7K4YYUzS3UytrCwczqMAsrN8RCROCbMiq5TgqtKWjyzi/ELy xxH+KnvTqkxxZM0zu2HXJWNQoxcoTrA7oKUudFTKziLYqApQSglPyUU7Ik8LCicNN9bf C4YA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si6221505edd.90.2021.01.10.09.46.15; Sun, 10 Jan 2021 09:46:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbhAJRoK (ORCPT + 99 others); Sun, 10 Jan 2021 12:44:10 -0500 Received: from raptor.unsafe.ru ([5.9.43.93]:38404 "EHLO raptor.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbhAJRoJ (ORCPT ); Sun, 10 Jan 2021 12:44:09 -0500 Received: from comp-core-i7-2640m-0182e6.redhat.com (ip-89-103-122-167.net.upcbroadband.cz [89.103.122.167]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by raptor.unsafe.ru (Postfix) with ESMTPSA id 0BE5520A16; Sun, 10 Jan 2021 17:34:52 +0000 (UTC) From: Alexey Gladkov To: LKML , Linux Containers , Kernel Hardening Cc: Alexey Gladkov , "Eric W . Biederman" , Kees Cook , Christian Brauner , Linus Torvalds Subject: [RFC PATCH v2 3/8] Increase size of ucounts to atomic_long_t Date: Sun, 10 Jan 2021 18:33:42 +0100 Message-Id: <2868ed8e8f196ae6ff4de60934668483680df14d.1610299857.git.gladkov.alexey@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.1 (raptor.unsafe.ru [5.9.43.93]); Sun, 10 Jan 2021 17:34:52 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit is preparation for migrating rlimits counters to ucounts. Signed-off-by: Alexey Gladkov --- include/linux/user_namespace.h | 4 ++-- kernel/ucount.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 483568a56f7f..24b850c7b70e 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -85,7 +85,7 @@ struct user_namespace { struct ctl_table_header *sysctls; #endif struct ucounts *ucounts; - int ucount_max[UCOUNT_COUNTS]; + long ucount_max[UCOUNT_COUNTS]; } __randomize_layout; struct ucounts { @@ -93,7 +93,7 @@ struct ucounts { struct user_namespace *ns; kuid_t uid; atomic_t count; - atomic_t ucount[UCOUNT_COUNTS]; + atomic_long_t ucount[UCOUNT_COUNTS]; }; extern struct user_namespace init_user_ns; diff --git a/kernel/ucount.c b/kernel/ucount.c index 80a39073bcef..4c5825ffd2e9 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -185,14 +185,14 @@ void set_cred_ucounts(const struct cred *cred, struct user_namespace *ns, kuid_t ((struct cred *) cred)->ucounts = get_ucounts(ns, uid); } -static inline bool atomic_inc_below(atomic_t *v, int u) +static inline bool atomic_long_inc_below(atomic_long_t *v, int u) { - int c, old; - c = atomic_read(v); + long c, old; + c = atomic_long_read(v); for (;;) { if (unlikely(c >= u)) return false; - old = atomic_cmpxchg(v, c, c+1); + old = atomic_long_cmpxchg(v, c, c+1); if (likely(old == c)) return true; c = old; @@ -209,14 +209,14 @@ struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, int max; tns = iter->ns; max = READ_ONCE(tns->ucount_max[type]); - if (!atomic_inc_below(&iter->ucount[type], max)) + if (!atomic_long_inc_below(&iter->ucount[type], max)) goto fail; } return ucounts; fail: bad = iter; for (iter = ucounts; iter != bad; iter = iter->ns->ucounts) - atomic_dec(&iter->ucount[type]); + atomic_long_dec(&iter->ucount[type]); put_ucounts(ucounts); return NULL; @@ -226,7 +226,7 @@ void dec_ucount(struct ucounts *ucounts, enum ucount_type type) { struct ucounts *iter; for (iter = ucounts; iter; iter = iter->ns->ucounts) { - int dec = atomic_dec_if_positive(&iter->ucount[type]); + int dec = atomic_long_dec_if_positive(&iter->ucount[type]); WARN_ON_ONCE(dec < 0); } put_ucounts(ucounts); -- 2.29.2