Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4724204pxv; Tue, 29 Jun 2021 14:06:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZydcEf+gLnnC+SQHYg5Dbxh/U7zVj0AWsyWeXBU2JJZU8GABFeuupVplEflX+DuM1/leU X-Received: by 2002:aa7:d853:: with SMTP id f19mr42475320eds.1.1625000780484; Tue, 29 Jun 2021 14:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625000780; cv=none; d=google.com; s=arc-20160816; b=KDaejZAFmMfHfOGDgxVDIJouQkPeWchps6ckhoFqonZDXoKIn7PjY+HGu+tS0Mj6z8 hTFMHn89WXdCqzt0N0VcMkGo3oU9AQ7C+/sfjHGXyLsSOQlfu4nreqWzQTsNs6hZyd6J AAfX3TtpC4ZmRne7y1pU6EH1gZUbmvXQacZw/+D52zvOLlB3bw1ECul8Z62lphSTBvyo nK55OeCGXlTbo5HFmDTodah52oxaIh1s+GnDeCK4k7MBQpWiVQkgJT4aos7o6ZaoJ1L1 bY+YqZlLP0Z262doNGNhTYJJ/FiT3VAJvLPiegd955NEr5j9mmXoiUBL4aq61kuUDTjZ DO1A== 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=x55tUBb2AfihnTgSgR9qFc+hjbodR7ZtsMX+vTUpjzs=; b=a6HyLY8/r7nRqxRO6TETFQb3ejMvwxcreuhA2G2h6jmzKdsYyJwgWhs6H1MAzQ1m0t LEK+C4ZHV0wfnf+VPFcntTG6TFQVoSHzLUNXY3DXXpIP4rETa3cDWD43fx5oPPdk+M5m 5xWFiASYstct72C766N2aOWpm41pwT1o2Mib3Ba7md+9bGHG7JkbtPpzecVD/qZa/AtT ynFVbDNGeKoPcog+NNbcqSyyyKC6M+kO8kFJA/dnRLcTFrzwZqBWwZRjG9EZXYQXhmf/ eBbeixRJG1znHvIQcNR70zAFyzkyLq0ZRQOSoQmj8em89hMeFvDuKtkRdv+xRxN+dYck l/Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RATlm6Zf; 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 ia23si18846692ejc.8.2021.06.29.14.05.57; Tue, 29 Jun 2021 14:06:20 -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=RATlm6Zf; 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 S235193AbhF2UW7 (ORCPT + 99 others); Tue, 29 Jun 2021 16:22:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:44048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233487AbhF2UW6 (ORCPT ); Tue, 29 Jun 2021 16:22:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1BA3861D8C; Tue, 29 Jun 2021 20:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624998031; bh=bICSGDYFeSkCNUGnuvKNS7/wSSeOYM2U/FpPXiDmJgA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RATlm6Zf8tzxMTcLPSAQjL1NtGvovqj51un+T+TbgGoACI9EJPlJUydfCOQhAoOve LImjE5NNPEnrwC5jrxEUiXw1epfAXG9ErX91m/i+kpuAZsiVmAmmOt1Q+x7oS54KcS h9zBSm9hzgc5gFg70POaQeuzH3B1hIQRu2wHoESrx30VR+utvNP/bO8O1Vf7dUm9bH mAKYFMvykaXSLjuKgSVXO1xxNakdIiqT8ySa9dx9uBJFeoJHR4daQQwR7mFN/UAbCD +qoBiaiB4ha2p1dwAbt/7h3TDpQypg9SjaK+dZtGttgky96ubTzgLm0Zpn3y/EXUp1 rcrtXGKGWOgUw== Date: Tue, 29 Jun 2021 22:20:28 +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: <20210629202028.gduluywejae75icj@example.org> References: <87fsx1vcr9.fsf@disp2133> <20210629171757.shyr222zjpm6ev5t@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 11:07:11AM -0700, Linus Torvalds wrote: > On Tue, Jun 29, 2021 at 10:18 AM Alexey Gladkov wrote: > > > > > > > And why test for "ucounts" being non-NULL in > > > > > > if (ucounts && dec_rlimit_ucounts(ucounts, > > > UCOUNT_RLIMIT_SIGPENDING, 1)) > > > put_ucounts(ucounts); > > > > > > when afaik both of those should be happy with a NULL 'ucounts' pointer > > > (if it was NULL, we certainly already used it for the reverse > > > operations for get_ucounts() and inc_rlimit_ucounts()..) > > > > The get_ucount() can theoretically return NULL. It increments the > > reference counter and if it overflows, the function will return NULL. > > .. but my point is that dec_rlimit_ucounts() and put_ucounts() should > be fine with whatever get_ucounts() returned. No > > It looks like put_ucounts() is unhappy with a NULL ucounts argument, > but I think _that_ is what should get fixed. > > I think that conceptually we should have two clear alternatives: > > (a) either "get_ucounts()" returning NULL should be an error, and we > would have returned long before get_ucounts() in the __sigqueue_alloc() performs the get_uid() function but does not ignore the counter overflow. Basically get_uid() can fail in same way as get_ucounts(), but we just ignore it. > or > > (b) a NULL uncounts is usable, and a sequence like > put_ucounts(get_ucounts()) should just always work. > > And honestly, a lot of the other ucounts funcrtions seem to take that > (b) approach. Example in that very function: > > ucounts = task_ucounts(t); > sigpending = inc_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, 1); > > which at no point tested for NULL or returned an error. 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. 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. > (And that also implies that the comment in dec_rlimit_ucounts() about > "Silence compiler warning" should just go away, because it's not just > a compiler warning, it's a required initialization). > > Linus [1] https://lore.kernel.org/lkml/CAHk-%3dwjYOCgM%2bmKzwTZwkDDg12DdYjFFkmoFKYLim7NFmR9HBg@mail.gmail.com/ -- Rgrds, legion