Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1445703pxb; Mon, 22 Feb 2021 02:00:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZtmmReLvcd32NikwqhJg8lPBOQbpw5kLpi9vi2vtzhCl58sSoi/747nDTW2V5lZClOdcc X-Received: by 2002:a05:6402:497:: with SMTP id k23mr21506510edv.315.1613988011517; Mon, 22 Feb 2021 02:00:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613988011; cv=none; d=google.com; s=arc-20160816; b=k8J98Q88ykA7PLnIaQ0KG4O5QTFWy7KP5KcLEC726hcIcR+UOgkgVkjwJp4ki/L3LB yWpBkNCKufIla2AHgpp2pt62vbpiO/ymdzeweuyRXoafQayeptx8sDVOWsEGD+cTC0FZ 2cWDxySLsbWjZori8sFL7AT7zRf+oAY0eUrjEzImyysC2kaIUWhXTlwP7T8SrZibAToZ ptgzALdBykUbmntVCC4g6v1SXdV8Ys2JjO6op/BkOYfFP4a6N+ZCenPpZMMiF2LbQBGy odb1+r3lacZDhxYADN2+/J4qLs1ClMHvipn1F5ye5PPRA38gwmYUrumcthTMVbipdV81 X5Aw== 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=IHlM45UG1/yePwDLavbLKOXlhkpMHul9iki68OC8fkE=; b=EB59ujhUWAI5CoahuZOHeuqcshn4ga8fJuB+TDWr/jC5jDsA+OXOpdOncfDRFhfxtE z+gjGP/MEapQys+21q6+yQBegow5u1FAyohuIkJ28rWBRrUI4QGzpZwnlK28Gjsjyqwq jr2vhMT/gCRvQA2jzpHua8xqaIYo/dFb6VXyFl8nl+mYUqa5OnU/7N5ZfZ+A+pIPcWor vTht74QYFBibcRP2VLNHgq9MXvElUB+GRrSmd16NXeNlWz6fdwD7tKCdtywjcjwofMGK Di9jy3oTHhUjQelMIWVg7fU5bVt2ANopk1g8+vLNWDWf51eKTBoMrR+gZDplNB8cXFSz 6m1Q== 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 j16si13393665edw.334.2021.02.22.01.59.49; Mon, 22 Feb 2021 02:00:11 -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 S229518AbhBVJ6f (ORCPT + 99 others); Mon, 22 Feb 2021 04:58:35 -0500 Received: from raptor.unsafe.ru ([5.9.43.93]:51304 "EHLO raptor.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230205AbhBVJ6D (ORCPT ); Mon, 22 Feb 2021 04:58:03 -0500 Received: from comp-core-i7-2640m-0182e6.redhat.com (ip-94-113-225-162.net.upcbroadband.cz [94.113.225.162]) (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 9396D20A04; Mon, 22 Feb 2021 09:57:11 +0000 (UTC) From: Alexey Gladkov To: LKML , io-uring@vger.kernel.org, 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 v7 1/7] Increase size of ucounts to atomic_long_t Date: Mon, 22 Feb 2021 10:56:26 +0100 Message-Id: <18b439960a2de06e9352c36b8d04fb149a024a86.1613987704.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]); Mon, 22 Feb 2021 09:57:12 +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.2