Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp124087pxf; Wed, 24 Mar 2021 00:29:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy32CCnRFVBHmUzqh+Ac3klzicAnQoFoL8u2Ij5Q0Vtz/zJ8FjTyqDc7B74vpnm7rKme5aX X-Received: by 2002:a17:906:dfcc:: with SMTP id jt12mr2210309ejc.31.1616570955316; Wed, 24 Mar 2021 00:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616570955; cv=none; d=google.com; s=arc-20160816; b=MUxAIpRm5PKJo2GnYpiYPMKcEbBY28gnyVgx0NJ0dQKJwPeaN4bd4/a0Caco98oWmw lPkOYH/NmIiasvhq2+ctPuvFQyDCkrGc4bHmggdiZF3LGJxJG3c8giDqBwK5I9B7ViMb JjGyNqzkKlVJWCWys+qelg58zx2pp5O4R4/FTwi8Zq0tu8IflJg0XfPzQL9wlb4aP98i luYV4r0MswLFdkIyvDXyMfxuq/Gt7mru//BDedOPF1ab2HIgECChJowk+Xh9UVaEz4oT 2iXsPlny1TSB6QbHx4piFPTFXdLxdWbOCcubb4g4YssFYcQJuIvkbwx5CuvR5VFqf2QN kxHw== 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=XEEVQqLRKUWaS5MlyFTXe5U8poxtkD800OPIZonpOV4=; b=CZXoK3VaC2wLRLoBu/mIgsIWk0K72E7K8Ds+GSm9Kq+XRhJ4qliLFsz7txYVc86rdn WroC7tKGFA+NFQRUdaBXzvY1MfoBQc3dzctyOfaJ10x4TSyG6qhmrdsVO4Wj78wDWKDH oVN5qTi8QXp1L2qohvLSOkRoL2pd958JNeEIlFQbjAefM26420wOkAXq6/VoUy+5W2+e 8C+lypIIhjwU788Q+hKE4li4zNsuyjwHzq67OrE4buUVTnyFBj39CqYZBHHITXQMQTv6 4uPKD1TLmDslxyKJHI31A7lr8W5zLYCYiKdTbjj5+Bk8DJn3d0rXi7Uo/0Q9/0NQYARK /LdQ== 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 f16si1337716edj.210.2021.03.24.00.28.52; Wed, 24 Mar 2021 00:29:15 -0700 (PDT) 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 S233466AbhCWVAY (ORCPT + 99 others); Tue, 23 Mar 2021 17:00:24 -0400 Received: from raptor.unsafe.ru ([5.9.43.93]:50020 "EHLO raptor.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233365AbhCWVAL (ORCPT ); Tue, 23 Mar 2021 17:00:11 -0400 Received: from comp-core-i7-2640m-0182e6.redhat.com (ip-94-113-225-162.net.upcbroadband.cz [94.113.225.162]) by raptor.unsafe.ru (Postfix) with ESMTPSA id B2C5E40C8E; Tue, 23 Mar 2021 21:00:07 +0000 (UTC) From: Alexey Gladkov To: LKML , Kernel Hardening , Linux Containers , linux-mm@kvack.org Cc: Alexey Gladkov , Andrew Morton , Christian Brauner , "Eric W . Biederman" , Jann Horn , Jens Axboe , Kees Cook , Linus Torvalds , Oleg Nesterov Subject: [PATCH v9 1/8] Increase size of ucounts to atomic_long_t Date: Tue, 23 Mar 2021 21:59:10 +0100 Message-Id: X-Mailer: git-send-email 2.29.3 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.4 (raptor.unsafe.ru [5.9.43.93]); Tue, 23 Mar 2021 21:00:08 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org RLIMIT_MSGQUEUE and RLIMIT_MEMLOCK use unsigned long to store their counters. As a preparation for moving rlimits based on ucounts, we need to increase the size of the variable to long. Signed-off-by: Alexey Gladkov --- include/linux/user_namespace.h | 4 ++-- kernel/ucount.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 64cf8ebdc4ec..0bb833fd41f4 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; int 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 11b1596e2542..04c561751af1 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -175,14 +175,14 @@ static void put_ucounts(struct ucounts *ucounts) kfree(ucounts); } -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; @@ -196,17 +196,17 @@ struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, struct user_namespace *tns; ucounts = get_ucounts(ns, uid); for (iter = ucounts; iter; iter = tns->ucounts) { - int max; + long 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; @@ -216,7 +216,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]); + long dec = atomic_long_dec_if_positive(&iter->ucount[type]); WARN_ON_ONCE(dec < 0); } put_ucounts(ucounts); -- 2.29.3