From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71964C433DB for ; Tue, 19 Jan 2021 04:35:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F1E9C20848 for ; Tue, 19 Jan 2021 04:35:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1E9C20848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaiwantech.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1FDDB8D002C; Mon, 18 Jan 2021 23:35:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D5726B006C; Mon, 18 Jan 2021 23:35:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EADD8D002C; Mon, 18 Jan 2021 23:35:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id EF0FF6B0031 for ; Mon, 18 Jan 2021 23:35:29 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A7D7D180AD830 for ; Tue, 19 Jan 2021 04:35:29 +0000 (UTC) X-FDA: 77721260778.29.duck31_43086032754f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 8F2A9180865B2 for ; Tue, 19 Jan 2021 04:35:29 +0000 (UTC) X-HE-Tag: duck31_43086032754f X-Filterd-Recvd-Size: 4982 Received: from sg2plout10-02.prod.sin2.secureserver.net (sg2plout10-02.prod.sin2.secureserver.net [182.50.145.5]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Jan 2021 04:35:28 +0000 (UTC) Received: from mail-ot1-f48.google.com ([209.85.210.48]) by :SMTPAUTH: with ESMTPSA id 1ijglAmDMxz4B1ijjlUIX5; 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=4slhDwrGXrWGs/SUwNzzxQ==: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-f48.google.com with SMTP id f6so9376292ots.9 for ; Mon, 18 Jan 2021 20:35:23 -0800 (PST) X-Gm-Message-State: AOAM533vpUcloQwePznBpEJvCDrNNHYkB0zySl8m4fVE+paphnJMxw2g MHLKhfgfw4j20wnJAAJ12dqE0hO8+x7rwEa8Ct0= X-Google-Smtp-Source: ABdhPJz0r7vrYUw3z7gsYPwKEPEVuiSgalGCOodz7zAs+w8wsmDs5ru5RxydNPiwFhVZ8XJd00vziAdKjyYOqXKV72E= 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: MS4xfBuCjVuUNzQ9MWUWLlb8iVSUpyoTLrRRPg51VIhbGaS7PWnxXk05EeWo2TWuAfS7NJX5WoX91oDc/wvqUUGl8a2YFw2PQhqIsH8f9M0so4KpBWGPfZtN uKjX5n07XVGptrYG1qXt4sNVEpRcAykG6CqSnk8jWMnwuDmHUQKTmu3Qt5ZLP90sNtKIb/vBYHm1IAnYPpyykHxSqahKaQ13Q3E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: (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 > >