Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3484967pxx; Mon, 2 Nov 2020 10:05:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfR1J3qB/HcXCCaK2uznFvQlFYTfyXTUgWD1g0H4v9P2wk2y+h6Eesl6GDboPCDJvZhmGO X-Received: by 2002:a17:906:519e:: with SMTP id y30mr16114688ejk.186.1604340323900; Mon, 02 Nov 2020 10:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604340323; cv=none; d=google.com; s=arc-20160816; b=HAdYjoVett6DjZ3zy/j25oCQE2Jf5dBN6eP8kcxhtlDojVRQx7Cj+d8A+NeroUv8iO EX+WDKDSyN2vtun2AAAAZ8UWOCcuTKe66oxl/kQtBZILu9VAZl1dbzfdhrQ4w38AopYG vAUYyNFsYJrT1PR2iJS6X3ZcTjOyOpf2zGnto6+es/rBMZXL4Mq68l+34+HXpcv00RAp AAVO2voWaGSeio1wEzKVfyMG0HeCWf5rNHXhR1+qSD+qPJ+e7yv1oq3gc4eMjI35Tl31 Qi1YsAOFsXfnxc1OWWb+ekZB9YtvKIiUrY/OEFxirD0Q93ner5NxAHO9568iD+YscURb ZV/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=1pCfHtSDp2/Kk/Iu2QSkmNQxVAbWMMs6bDS8vkhukus=; b=DpDQuBc8mKSsfjBi4pbWaO529ISs65AA2B500iuhWggK1+rAgAIVQF3/jK3XpnSner hjdn/ZHzc3T8yEAkYwdBVI9BDaQXlcNSFUkGwbmAH3Cw8kUTfy1xnePiYmLclHzBMnwO gkaChhgDvb+RckOriv5nUpfKp5nqcpgDRQP5vPbzHLk96MXn3Jr7KeWQ/GX4LUmfCmtz Anr4/mzvxlY14dEAlsf9HzMT94GRKgtaoPWVg1e6nVx/ARpkufiqeUTyZZGVhc9oJFSJ LqHWjxi4DjGc/DDe6WDyWTtHp/FPBfHYpjIwKihi34/YzNInmuW+qW0kgBTCyNpO9JNs iiJA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si10989747edq.501.2020.11.02.10.05.00; Mon, 02 Nov 2020 10:05:23 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726166AbgKBSDF (ORCPT + 99 others); Mon, 2 Nov 2020 13:03:05 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:58012 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725926AbgKBSDF (ORCPT ); Mon, 2 Nov 2020 13:03:05 -0500 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kZeAZ-0004RJ-CZ; Mon, 02 Nov 2020 18:03:03 +0000 Date: Mon, 2 Nov 2020 19:03:01 +0100 From: Christian Brauner To: Alexey Gladkov Cc: LKML , Linux Containers , Kernel Hardening , Alexey Gladkov , "Eric W . Biederman" , Kees Cook , Christian Brauner Subject: Re: [RFC PATCH v1 1/4] Increase size of ucounts to atomic_long_t Message-ID: <20201102180301.dup2cmbqdyrexp22@wittgenstein> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 02, 2020 at 05:50:30PM +0100, Alexey Gladkov wrote: > In order to be able to use ucounts for rlimits, the size must be increased. > For example user_struct.mq_bytes (RLIMIT_MSGQUEUE) is unsigned long. I don't have any issues with this change I just wonder what the exact reason is. It's not immediately obvious to me. > > 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 6ef1c7109fc4..fc75af812d73 100644 > --- a/include/linux/user_namespace.h > +++ b/include/linux/user_namespace.h > @@ -86,7 +86,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 { > @@ -94,7 +94,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..7b2bca8582ef 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; > @@ -199,14 +199,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; > @@ -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]); > + int dec = atomic_long_dec_if_positive(&iter->ucount[type]); > WARN_ON_ONCE(dec < 0); > } > put_ucounts(ucounts); > -- > 2.25.4 >