Received: by 2002:ab2:7444:0:b0:1ef:eae8:a797 with SMTP id f4csp26287lqn; Fri, 15 Mar 2024 11:41:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUDgH+hFY0zLaok3dKdbFc5r9mOgRPf0FvhEW48PLFIF2UD6LJkdv6fsJhEKSLqvs1rPxegflUC9h+iTJunr+ZDu2DXSrinW8X5l72b0g== X-Google-Smtp-Source: AGHT+IHSdsCXGy0Iy1fv9Ni97Mw6PC7szpk0r9bT7znhS4UPcM/eKW+aFFY+ezifO0AGeRI7+n3b X-Received: by 2002:a17:903:1249:b0:1dd:abb1:e02 with SMTP id u9-20020a170903124900b001ddabb10e02mr6233248plh.43.1710528119526; Fri, 15 Mar 2024 11:41:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710528119; cv=pass; d=google.com; s=arc-20160816; b=ifZwlglfb1wUicYxFu9RPMxlyov1V09R1bufkG05POITa0yj1gKGfzzlNinByS1IFQ ermKNYObu19gcxhMZ5asGWs9CQ3JhzyZ1EMnIg444lBle5il6O5luNQ95HYSEZV8AeC3 8NgFV3eTAD0oU8Vt76l+WoJ3Uc0d+l6cOMLg4+GkPF/dN4tqIK8PhZ/QjOg70wGLAHCR jFfI9Mc/8wl5f3u+0Pdy/TTFdAA44V9PN18lbexKBkkR3WUDnwyPzjiZi40loEFJauAc NX+f7rac+2is6Gc/mPpunVAFQ598T//kOONKbOtBT5Snbd+XXRDhwLifGAXrFKEg2k9d YYCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=0lOi8R60F8R8EFdifsjdi6HEQyuwBQcJc8tV69kgjLY=; fh=9aP8m8Uuw7hH6Oe3SGk2f/jRgkwaGqI/VMLXlBq2wac=; b=eClctU9lkb+rORDNhheX6TF1KLRkX0dihTrd1Is9VTY10POfj2B9VrTlWVQLAVOfif 275dwHbilJY9Q/yEgbjJuCf2q6nQuA0kzy08P9BqIxtlRNVIeiBilXMXsJwIANpceKpd a+cedDeQ7N+3apK4dhdO3EWJa2p52SDiCBNpe0dn1UfRiNloeakD/nweTQ/qlWlsrghv XGGfjfsBs7gtc4NDVlrMkWTyzTklhA5eBH4SKSIwwm5G+rW3beTVDAuNRsesY2VTS3oL k7EH2dkjOADA4MQEodgMHu5dVI3b5ZhfPlyOb6ybykjXdVnuJbCHV2P9I3/xivf7LWdg uvqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=dSI1gJOR; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-104797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104797-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s6-20020a170902ea0600b001dd5f7a9e9asi4131878plg.437.2024.03.15.11.41.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:41:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=dSI1gJOR; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-104797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104797-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3AF8C28569E for ; Fri, 15 Mar 2024 18:41:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F9A33EA77; Fri, 15 Mar 2024 18:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="dSI1gJOR" Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 B19F414A9F for ; Fri, 15 Mar 2024 18:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710528105; cv=none; b=bIqAVHnfrntobBxogs4cnv2t/q2KfyepLWo2lruZPPSrNVnaOScOgTJoFikzKnemz6FgLV6Suq9LC647vLGKF2ccCklcHleBuwc01qc6+qZXQHa2Fh1crSZyOxHQ7fHh1ml72vaRGMjQI41uThPlwYc4hgJ8/noP5cd5rDLjKE8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710528105; c=relaxed/simple; bh=6sNODvKTQ/pBcJxGo+BJkhwoG4FuMEJkTeFd/S8dXhE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=R+UNC2v51GW0OS3QmMfuiemZS5TkbMedFIJO21YQqF8rFWfP65hjuknP7lR5X5EUjHcePs6Z8Q5HlmjRnJumF70XOg8lzi9YLiam5ExhJb1qhi7M4mNB9hFxDoErDlBt5tIBLChW3JzpYRHYosRObyhuq/W4bmeyhCN3oKtRH/k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=dSI1gJOR; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6e694337fffso563046b3a.1 for ; Fri, 15 Mar 2024 11:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1710528103; x=1711132903; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0lOi8R60F8R8EFdifsjdi6HEQyuwBQcJc8tV69kgjLY=; b=dSI1gJORgoMO+XscvAHQ6cwDHMuDlg73VPSZTJW66ksBYfmYH0teBMk5NxsUWCro+9 j+sQ/MGxJa650SImSQZF3JfDFt02jXyqvDJM69vxoUo5GhDZGnGSejtiOM6f7LeVAV11 I5zWeK0g3vkqk/A82jk3TRbx6co57PEhmHJMO3DvHtzebJGKPGZQIAPzkDLXziuUVe+i Z2qf9a8EYjIFOJkwIs6l9h4GB2dtYWIpL3vNfW6pWNwPVl41r7at4QOSLwWIZGLjs+Aa VRRHacbPyQWc12JHtzEvSG85wwtuo0W8AspXKR2YpPelEDGbp11jznaWKE7gd6HZsSEA gqyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710528103; x=1711132903; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0lOi8R60F8R8EFdifsjdi6HEQyuwBQcJc8tV69kgjLY=; b=AM9FGeA10ipLfAl8Y4IjF9YssZkC3tFtTb14sfKBjsyTIEvSz6YlyBwxkWm+4QKdYF y9v1KTeWVP1q4l8O3YvDCU3DAiK8Efu2KogYwYJgBSMX+/ALgNaYrXLMS3MAsUFBY9L9 V4paVf8jEC0DizLLaj+5RBGehWyZOBYQT/YE6M3faGm3QhgUCRuE0EC4mW1u2ZBQWDlh 63t9yRwry4VnxjKdElApp4lWftefkxwsUoLM7nakaEoFZ35n4nAcByfFP3RU+tUYv1uf JfhW3bSdYFWKlwu4cbceVf+NkPGsoXlhOxL75VseQV0S5keQKIL4kbfmoufFJ+dbp2gL HLBQ== X-Forwarded-Encrypted: i=1; AJvYcCXQoUj4IN56CIIVzZGkCQB0De9vkplHjfHhqz1KWQK1PcEn+NbWUWfK8MHFbN5hz/1Br7eLxSlrQhgt1Y1b6GaE8cXSXvqlCalAdGXu X-Gm-Message-State: AOJu0Yy6fbRyxygcKOkySTmzPqtHKB+el2n1hoJUtvjgX6qocGORhOlk KoeqkWrMjQSvr/GiT+2zRU1zGzE3c2Zj0dMrPZKYbHEJYZZgaawjWE6zJoa9MYM= X-Received: by 2002:a05:6a00:2d07:b0:6e6:8954:b9a6 with SMTP id fa7-20020a056a002d0700b006e68954b9a6mr3383297pfb.1.1710528103048; Fri, 15 Mar 2024 11:41:43 -0700 (PDT) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id ln17-20020a056a003cd100b006e6bcbea9e0sm3716680pfb.88.2024.03.15.11.41.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Mar 2024 11:41:42 -0700 (PDT) Message-ID: <0f8291f7-48b1-4be1-8a57-dbad5d0ab28c@kernel.dk> Date: Fri, 15 Mar 2024 12:41:41 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 02/10] capability: add any wrappers to test for multiple caps with exactly one audit message Content-Language: en-US To: Andrii Nakryiko , =?UTF-8?Q?Christian_G=C3=B6ttsche?= Cc: linux-security-module@vger.kernel.org, linux-block@vger.kernel.org, Serge Hallyn , linux-kernel@vger.kernel.org, bpf@vger.kernel.org References: <20240315113828.258005-1-cgzones@googlemail.com> <20240315113828.258005-2-cgzones@googlemail.com> From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/15/24 10:45 AM, Andrii Nakryiko wrote: >> +/** >> + * ns_capable_any - Determine if the current task has one of two superior 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 permitted, >> + * 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 == 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? 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