Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp36853lqb; Fri, 15 Mar 2024 14:17:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOEf6fJbTDlYj2EijCRrGYEIt4bsPFeGi8jEhrBScc+kODiYCbSG5J/8GZOV4Bua78zBS+RbleS4ZLLHD+JyfP2IC+9V3nfcEyqcSlfA== X-Google-Smtp-Source: AGHT+IGo1/906ZCvbcftwnoVgnYCjB2TqLt8ZUqgq2DFXy5uLrdy853sWTsAzEKggrYNjT6Qgx0k X-Received: by 2002:a17:907:7e9f:b0:a45:ad00:eade with SMTP id qb31-20020a1709077e9f00b00a45ad00eademr3516825ejc.57.1710537452968; Fri, 15 Mar 2024 14:17:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710537452; cv=pass; d=google.com; s=arc-20160816; b=Bp8MOLcBSoX0ce+VRVKz+yrU7xf7RkB/kD7FeR6TcKEctREWrhSW5pi/W7FqnfOPLT IZ3ZvX+gee/HNgemYCYDItLojjFHcgY5juhJeCrDKZrDNdpyOa+3sWNdy0XP8MVby238 3ULINiy2IC3pytxRjLxgq2Kb4GDuL/hZjBhEj+Rww3Su2NnRccgjCGaty62rhlCH0QWK zoFU85q8DilUPcry4vSHNZojQ+oEehEiWTXHGk9T5g+TBAUWmvbd0PK1HxonVM2peLnC DdoBkSgKc3KwDgsl/Y8sVl5ylAs8t7S2FxxipEwj4gKX3r0MUfiHa6HOOPL083qZYjgA jg5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=dbw37BmJsQeVdqK1E7BHtnCUQp5XmW43FRTZzRfLqog=; fh=wSdfARqgoGv7aZp5kJ5+Lq6ywRLbEhQG0loU0n2yxUA=; b=ZBk+FdEJ/QOP1e8dGsH4H9JSuhk57Am+qs+v2gDkjGCqZa0GV/ECsv8xvNM6SFkANH oTZkWYtIeRQX0NShxeNDjZOQVCsp3UXiAzbcicXGBljWUe0BocFn+sryOZJgWoNsUt/8 WddUs8O5RdD82JIdx3CuGX1d6isvrz8H8IB3GKrjQKquS4Qz+HEYLRRPv18C8qLbyjkB oT8pZ1P2D3N6oUu83GbcK8WGzRHBJpZlzr08ZutFs8vwzB29Ll8d2xZevoIcwVDfrfhg baiXqHR+u28jXXVErax5Wecn/HBj0UM4ANKj3O+d+acvr9adNaWhaRSY8V0aQnRRRb8g v+Zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="WASBOIO/"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-104931-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104931-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l12-20020a1709065a8c00b00a41308b6bdasi1994064ejq.260.2024.03.15.14.17.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 14:17:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104931-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="WASBOIO/"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-104931-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104931-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8D0541F210F1 for ; Fri, 15 Mar 2024 21:17:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E71454918; Fri, 15 Mar 2024 21:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WASBOIO/" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB00C548F0; Fri, 15 Mar 2024 21:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710537432; cv=none; b=oSnymNfDzb020l9NOeeXZT/FrhOrWXtzr5hQTU9Lxy+e1dLFV7HRCHno/Kz+mPbymGXc/6Juli3ovfod5FthB69OUQlIuSPuJ7Kst0xEIRlp2MF6+g+XxoNv3lI58Eu7ZL89OY/bTa+JRkuYmojczb0GWHRlq2dX1yerRgtXi0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710537432; c=relaxed/simple; bh=hwD/lGz/VzatlOJGLNO2bM+DjLMZEkNqMUkR6QXjBvk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EmKZ/0zBU5JIcy+mcbEoRyI53l+J2EZXBMeF7QvaEl212I6eO6XaXzzTzD1M7vbyJI/x3GWnp9sGfPmNeWCeifu46rHWOYi5sKqAFxV7UFXclb3xtAJFcJJ4yZ8NsZaFnPgeCDrkl0cJwadGATnk3jjJk/H0YerOqv6SExCltAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WASBOIO/; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1dd9b6098aeso19215645ad.0; Fri, 15 Mar 2024 14:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710537429; x=1711142229; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dbw37BmJsQeVdqK1E7BHtnCUQp5XmW43FRTZzRfLqog=; b=WASBOIO/mk8BOl/FGa78H6u+IUALpPqN0Qt30t5ECct3HdZ2wqtwhtbXDrna/n3cGk pjkV2cgD+E4iIS7AWk0dZK4cbRBKGCew5xYlHuZBhU5TDuQGpQxJmbjjgTaRuSiWJcO8 1W52bLKcN7cutPxLcPNiE3iaZqCqfdncGMBjnvRPS4uGwcsGvldPD2uhiMUbwgz922cv +kftX/2jr4wZVspG8EM6NeiYBnjCF36rooC3Uv9BIMjcmwYoPSlE2TpqMen9Ea4Us+2j nXnAo7ZLQjBRfdDiFjEEfs/yw0wJ5hUlEipiKTa13lOSUMgpPIQ2L9F01DIfBdVEizyE wQww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710537429; x=1711142229; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dbw37BmJsQeVdqK1E7BHtnCUQp5XmW43FRTZzRfLqog=; b=PGDhIhJV4YAlspWfXXC/d5bmOLA7U1z5aOHgzFqMa7UPaQg12iQNGsMHTau5Fg43zY tJFwVfeH8tmEO1j9uhK78PqCACITHBWAEJYY0GFxEYOumkVgH4lv/xR4oX+qvctmXxF/ zvBu80oL6k5QngESVgi/IX8PH4u06e5YUEsSxKjnvYjZKdPn8nlsLf32wyTyzKn5EjNS 5mnitQd/spRNEZugvyo//rJhG3TdYVcLAXkfMUTbhMozblLG8o9b+BIrNdRjEhGNs8m8 y7Bho6R5r0daRuRqL28/5ZlKXzO/AkJ633CTLtCNeGGO/A3zuGomJ+6FddmnuKelmt92 KnUQ== X-Forwarded-Encrypted: i=1; AJvYcCUt5opfCpfN8eT27H5L4ewgTcJdG9ZfmtqSKhC+W6KrBvqntatXtqmdbv0idSB7/CQZadO2Z+LtFlrCJ1tbGP+jslygs74lgwHQWxsxj/Jxs+DgJDRYldMwstjK/m/XdUszVqqE92yT1dyDstEYtE4yuXS68OX3ISHOoRjhTp290Zwt6z8nU0XGbcJxT5TgNYQjpRLbrvtDZi4vfdzVlKUDVETK1Mo= X-Gm-Message-State: AOJu0YxkEMw31ZKbxzXmWGOQt2SgtTNAaXZie8deiejH08uOYTdoDbmA 2m0JLl78RDINLPjjHNG+Ctc9vMgHgrxO8H/iwZ/s0SndIQs5csEl0IaLLnAZ/oSbvAlnRUL7A5p fuCXdUF2iPoOdZSAdNL3V2SrS+FEAxM+n X-Received: by 2002:a17:902:6e16:b0:1dc:ca1b:279b with SMTP id u22-20020a1709026e1600b001dcca1b279bmr5438447plk.1.1710537428873; Fri, 15 Mar 2024 14:17:08 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240315113828.258005-1-cgzones@googlemail.com> <20240315113828.258005-2-cgzones@googlemail.com> <0f8291f7-48b1-4be1-8a57-dbad5d0ab28c@kernel.dk> In-Reply-To: <0f8291f7-48b1-4be1-8a57-dbad5d0ab28c@kernel.dk> From: Andrii Nakryiko Date: Fri, 15 Mar 2024 14:16:56 -0700 Message-ID: Subject: Re: [PATCH 02/10] capability: add any wrappers to test for multiple caps with exactly one audit message To: Jens Axboe Cc: =?UTF-8?Q?Christian_G=C3=B6ttsche?= , linux-security-module@vger.kernel.org, linux-block@vger.kernel.org, Serge Hallyn , linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 15, 2024 at 11:41=E2=80=AFAM Jens Axboe wrote= : > > On 3/15/24 10:45 AM, Andrii Nakryiko wrote: > >> +/** > >> + * ns_capable_any - Determine if the current task has one of two supe= rior capabilities in effect > >> + * @ns: The usernamespace we want the capability in > >> + * @cap1: The capabilities to be tested for first > >> + * @cap2: The capabilities to be tested for secondly > >> + * > >> + * Return true if the current task has at least one of the two given = superior > >> + * capabilities currently available for use, false if not. > >> + * > >> + * In contrast to or'ing capable() this call will create exactly one = audit > >> + * message, either for @cap1, if it is granted or both are not permit= ted, > >> + * or @cap2, if it is granted while the other one is not. > >> + * > >> + * The capabilities should be ordered from least to most invasive, i.= e. CAP_SYS_ADMIN last. > >> + * > >> + * This sets PF_SUPERPRIV on the task if the capability is available = on the > >> + * assumption that it's about to be used. > >> + */ > >> +bool ns_capable_any(struct user_namespace *ns, int cap1, int cap2) > >> +{ > >> + if (cap1 =3D=3D cap2) > >> + return ns_capable(ns, cap1); > >> + > >> + if (ns_capable_noauditondeny(ns, cap1)) > >> + return true; > >> + > >> + if (ns_capable_noauditondeny(ns, cap2)) > >> + return true; > >> + > >> + return ns_capable(ns, cap1); > > > > this will incur an extra capable() check (with all the LSMs involved, > > etc), and so for some cases where capability is expected to not be > > present, this will be a regression. Is there some way to not redo the > > check, but just audit the failure? At this point we do know that cap1 > > failed before, so might as well just log that. > > Not sure why that's important - if it's a failure case, and any audit > failure should be, then why would we care if that's now doing a bit of > extra work? Lack of capability doesn't necessarily mean "failure". E.g., in FUSE there are at least few places where the code checks capable(CAP_SYS_ADMIN), and based on that decides on some limit values or extra checks. So if !capable(CAP_SYS_ADMIN), operation doesn't necessarily fail outright, it just has some more restricted resources or something. Luckily in FUSE's case it's singular capable() check, so capable_any() won't incur extra overhead. But I was just wondering if it would be possible to avoid this with capable_any() as well, so that no one has to do these trade-offs. We also had cases in production of some BPF applications tracing cap_capable() calls, so each extra triggering of it would be a bit of added overhead, as a general rule. Having said the above, I do like capable_any() changes (which is why I acked BPF side of things). > > I say this not knowing the full picture, as I unhelpfully was only CC'ed > on two of the patches... Please don't do that when sending patchsets. > > -- > Jens Axboe >