Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2523351pxb; Mon, 18 Jan 2021 22:10:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrIRRyyZ0YmpxuuUnZ7vLIaksFW0KzJOLRzy2dpU1ov6559Hbe5Cj2i4idhuhv22rDB6Sc X-Received: by 2002:a17:906:5958:: with SMTP id g24mr1906157ejr.377.1611036605064; Mon, 18 Jan 2021 22:10:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611036605; cv=none; d=google.com; s=arc-20160816; b=zmZIHEUdcq9yQ4OploaYAZKPFg+XrQJFiAvntnO0L/Qxyu586r3tpsxaCho34LwAdL Zzgve49tu1tLrWcTOMlIHcfkq7Nq/rBaHUNWnmx4FJhNIBWWGsaSseLOc52ItmzASbSR Mij7LqnQx+StY0uBCJVKuvYVVdhypm3Cs+yDF5aZmBG1NV/cY+IdVapHn5Xe3JGDmk6Q XZHDFGEeFQozO3RkOYkyvvirkvhD02OhrF4xlp6tUIKWxZD5OvY/IMDitKOKPIyayZJ0 b3cRG9eEsdJOcq736IgI/JO8gf1K6MBIS9+uE35wTvzNQNvHfTNrk+0N/jm0oNbUJ0D8 E9Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=ztUDKl7H89ITgaBbGB0Cp/jrXuxd61oq9RpsYef29kc=; b=oIRgJZhneF4/6l84jqqML5IP7NxVx9QUR5vCPzUFEbPjeNz2ux662kWlpbj7KpDN2P afPWMZ52VEH/Y4OutdvNVhNZNYwySuxN54dC2cjPsHB7p50t4H2j20FdCSMRVRrNYXXr 7S991TdkxDh0VnaBKlOFK+Q5rFe13O09nBUiaH349zZ+efYKNC/xaxxcgwC/RG8JSuQ8 8SxnVSvAVWofgq9Ez4Ksih0uSCOPMjtiNK5pn9UkpWfY4WFj8hgx+kzgzOwcrVrbB1Jz VngpvVljqI+dgajn7xZMWPCjZGQj8aQasKCpb4z+9WZwR44/KixxtiemtvCXYjZJZgkQ IHmw== 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 gt33si7818520ejc.320.2021.01.18.22.09.42; Mon, 18 Jan 2021 22:10:05 -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 S1729469AbhASFd0 (ORCPT + 99 others); Tue, 19 Jan 2021 00:33:26 -0500 Received: from sg2plout10-02.prod.sin2.secureserver.net ([182.50.145.5]:59460 "EHLO sg2plout10-02.prod.sin2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732137AbhASEpP (ORCPT ); Mon, 18 Jan 2021 23:45:15 -0500 Received: from mail-ot1-f41.google.com ([209.85.210.41]) by :SMTPAUTH: with ESMTPSA id 1ijglAmDNxz4B1ijjlUIX6; Mon, 18 Jan 2021 21:35:24 -0700 X-CMAE-Analysis: v=2.4 cv=SbAyytdu c=1 sm=1 tr=0 ts=6006618d a=PTypr3n1IRLBnQ3yzyqIcw==:117 a=IkcTkHD0fZMA:10 a=EmqxpYm9HcoA:10 a=pGLkceISAAAA:8 a=9vr8BnzVG96gFNSbxsUA:9 a=QEXdDO2ut3YA:10 X-SECURESERVER-ACCT: kaiwan@kaiwantech.com Received: by mail-ot1-f41.google.com with SMTP id n42so18564091ota.12; Mon, 18 Jan 2021 20:35:23 -0800 (PST) X-Gm-Message-State: AOAM5311zvsh950bILj656SOwg57D71NMDhnIjyUQwbSTDs458NjoB1H Yff/96XxcNLwEpvrJX3afd/ebhzlW0ihOWr+w54= X-Received: by 2002:a9d:2c43:: with SMTP id f61mr2091626otb.329.1611030919638; Mon, 18 Jan 2021 20:35:19 -0800 (PST) MIME-Version: 1.0 References: <116c7669744404364651e3b380db2d82bb23f983.1610722473.git.gladkov.alexey@gmail.com> <20210118194551.h2hrwof7b3q5vgoi@example.org> <20210118205629.zro2qkd3ut42bpyq@example.org> In-Reply-To: <20210118205629.zro2qkd3ut42bpyq@example.org> From: Kaiwan N Billimoria Date: Tue, 19 Jan 2021 10:05:03 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v3 1/8] Use refcount_t for ucounts reference counting To: Alexey Gladkov Cc: Linus Torvalds , LKML , io-uring , Kernel Hardening , Linux Containers , Linux-MM , Andrew Morton , Christian Brauner , "Eric W . Biederman" , Jann Horn , Jens Axboe , Kees Cook , Oleg Nesterov Content-Type: text/plain; charset="UTF-8" X-CMAE-Envelope: MS4xfBuCjVuUNzQ9MWUWLlb8iVSUpyoTLrRRPg51VIhbGaS7/r/JfQ4EeCJYJwI3C5A/3IGr0RrIOw/WjTnlGS70S+7fv4X0Xrk+mW7YC7iAJT50eyS+qwic JpjBaPm1nVA/UnSgdWar1vNFccMXyBSgHTghu7QmpGrKaXma+Nky59gOwDd9elXAgfw53u8nNqRUBKG4Qg+U/6BDfsBku39FmGkMXdC+8nj42UGYhK1DmD7I iWpBynvllxUgGzYNkx3+2Q== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (Sorry for the gmail client) My 0.2, HTH: a) AFAIK, refcount_inc() (and similar friends) don't return any value b) they're designed to just WARN() if they saturate or if you're attempting to increment the value 0 (as it's possibly a UAF bug) c) refcount_inc_checked() is documented as "Similar to atomic_inc(), but will saturate at UINT_MAX and WARN" d) we should avoid using the __foo() when foo() 's present as far as is sanely possible... So is one expected to just fix things when they break? - as signalled by the WARN firing? -- Regards, kaiwan. On Tue, Jan 19, 2021 at 2:26 AM Alexey Gladkov wrote: > > On Mon, Jan 18, 2021 at 12:34:29PM -0800, Linus Torvalds wrote: > > On Mon, Jan 18, 2021 at 11:46 AM Alexey Gladkov > > wrote: > > > > > > Sorry about that. I thought that this code is not needed when switching > > > from int to refcount_t. I was wrong. > > > > Well, you _may_ be right. I personally didn't check how the return > > value is used. > > > > I only reacted to "it certainly _may_ be used, and there is absolutely > > no comment anywhere about why it wouldn't matter". > > I have not found examples where checked the overflow after calling > refcount_inc/refcount_add. > > For example in kernel/fork.c:2298 : > > current->signal->nr_threads++; > atomic_inc(¤t->signal->live); > refcount_inc(¤t->signal->sigcnt); > > $ semind search signal_struct.sigcnt > def include/linux/sched/signal.h:83 refcount_t sigcnt; > m-- kernel/fork.c:723 put_signal_struct if (refcount_dec_and_test(&sig->sigcnt)) > m-- kernel/fork.c:1571 copy_signal refcount_set(&sig->sigcnt, 1); > m-- kernel/fork.c:2298 copy_process refcount_inc(¤t->signal->sigcnt); > > It seems to me that the only way is to use __refcount_inc and then compare > the old value with REFCOUNT_MAX > > Since I have not seen examples of such checks, I thought that this is > acceptable. Sorry once again. I have not tried to hide these changes. > > -- > Rgrds, legion > >