Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4742161pxv; Tue, 29 Jun 2021 14:36:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzbSlSVcw+TvdInjiI+tjL4soPEHi/l9A93s7XEES8+UKycVWAJ6oItdnszyqTfbhmQr9q X-Received: by 2002:a05:6402:214:: with SMTP id t20mr43516994edv.20.1625002570463; Tue, 29 Jun 2021 14:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625002570; cv=none; d=google.com; s=arc-20160816; b=IRbOVOisW5Kgww5lRYWEq0cRHm+owxK0P7zeLHp2M39Ui8YdOF/gSqA6HjI6rnPNxM 7665fE4sr7Luz9ZYoWoD0eGIZlzqbQEKgPGwJSNoEfIFThMOYyAtQ0UNBb1iZT1acnO3 R7HTSMdFlRPXPdlvmpf8dtvrx9IP1hIoOW4WzUA562JoQLHu5FQgdRARHtxkt7PWjh9U Aq2FJjV11JfRoiH7sgqR5dHD4a3HrhlY6TSa9DNgKYbwD05Nwe3im9G68wh1bzVJRYkn V0Eh1ZzhG8VCksivcMmtBsyk0HNnmvmb+ffe9DtRHe1D5sbD5VKSVYIpMLvvf47EvKlF ICjw== 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:dkim-signature; bh=ME6hug3fQb+OFXnYc4FUKEQt9lTiAxYtSNk4x3C4CLQ=; b=GgYiEyk5rwgRfr3lld6PjOOKR0mkkyB/DMI1nQUL20lmwXdrPo1s7/9jmDWLbpDn0C R3IrCzWzi3L04A5L44tlWilkZrr3mCX8ylOwSekdxOQfDZadKYDEiY3M+xFh8nx19lx5 svvWtMFRxMGq3F0dqjZLrgwppcjW+xNKIYiRWWK5dS896kZm9EFYwCP5xqkV6rJyZCmN nI+LhEpHynzcb2vh2MNl/wprwlrmMRNF603i4fkXRCzmIUR4Ld5AWzVImrb2QhiKcmTS jsunK3QpM4dZpwIceJa+eK8IZgEHhLgskh0GY+0/glvP5gE5vE9okbwr/v8OsZ6I8gAq ytww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DKxc6PAR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si19868569edr.112.2021.06.29.14.35.46; Tue, 29 Jun 2021 14:36:10 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DKxc6PAR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235941AbhF2VYv (ORCPT + 99 others); Tue, 29 Jun 2021 17:24:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:60058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235918AbhF2VYv (ORCPT ); Tue, 29 Jun 2021 17:24:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0F8261DA0; Tue, 29 Jun 2021 21:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625001743; bh=DASKGpMIPrP2jFKLyy4+IOkW669wEy21u5wK1pFUSt0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DKxc6PAR5H2fNFB1FwSxjgTDm9aqiE0K/UepIySbYe/1vPLUhsNrG8okJnJgI5uJW gKwnWrLizzHaGxmIl9uZh7gLOGvuBT6YUF4ZiM/B2MMz3pkOS8JBrAtoYbk8Ngiwb1 U9C81E2JLMWCns3rmrwp+TH71C3QKa3ymYAyoIfr8s70cKtOynqxSC0DZYdlw8u6l2 UYvO+xqiqmMECBsnfz09BkbN5HfGhmkYRqRykPQpUOAkTxv4Fk8gl5hyLB9jbpRR08 TWNS+yyXI2XeFS7e/KQTyelcCCpWD4mNF/v0k9XAPIM1+8zb5UqAuW8bU8dmiThAqH 21IGPypj97MiQ== Date: Tue, 29 Jun 2021 23:22:20 +0200 From: Alexey Gladkov To: Linus Torvalds Cc: "Eric W. Biederman" , Linux Kernel Mailing List , Linux Containers Subject: Re: [GIT PULL] ucounts: Count rlimits in each user namespace Message-ID: <20210629212220.itvtsqls4tnmrei7@example.org> References: <87fsx1vcr9.fsf@disp2133> <20210629171757.shyr222zjpm6ev5t@example.org> <20210629202028.gduluywejae75icj@example.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 29, 2021 at 01:33:39PM -0700, Linus Torvalds wrote: > On Tue, Jun 29, 2021 at 1:20 PM Alexey Gladkov wrote: > > > > Waaaait. task_ucounts() is a different thing. This function only gets a > > field from the task structure without any reference counting. But the > > get_ucounts() is more like get_user_ns() or get_uid(), but does not ignore > > counter overflow. > > Alexey, that code cannot be right. > > Look here: > > rcu_read_lock(); > ucounts = task_ucounts(t); > sigpending = inc_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, 1); > if (sigpending == 1) > ucounts = get_ucounts(ucounts); > rcu_read_unlock(); > > so now we've done that inc_rlimit_ucounts() unconditionally on that > task_ucounts() thing. > > And then if the allocation fails (or the limit is hit) the code does > > if (ucounts && dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, 1)) > put_ucounts(ucounts); > > ie now it does the dec_rlimit_ucounts _conditionally_. > > See what I'm complaining about? This is not logical, AND IT CANNOT > POSSIBLY BE RIGHT. > > My argument is that > > (a) the dec_rlimit_ucounts() has to pair up with > inc_rlimit_ucounts(), or you're leaking counts > > (b) get_ucounts() has to pair up with put_ucounts(). > > Note that (a) has to be REGARDLESS of whether get_ucounts() was > successful or not. > > > Earlier I tried to use refcount_t which never returns errors [1]. We > > talked and you said that ignoring counter overflow errors is bad > > design for this case. > > You can't ignore counter overflow errors, no. But that's exactly what > that code is doing. > > If get_ucount() fails due to overflow, you don't return an error. You > just miscount the end result! > > So yeah, its' "testing" the overflow condition, but that's not an > argument, when it then DOES EXPLICITLY THE WRONG THING. > > At that point, the test is actively harmful and wrong. See? Yes. Please, give me some time to fix it. -- Rgrds, legion