Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp22392rdb; Wed, 21 Feb 2024 15:39:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVglIiejzStM159kCttELcnz2zJmA9xABewnr9pd6Ixsyo5/BAwgZdvcgMEfW8zCZ/wQGMZpJ7yyAGTElOx+xQd6d6Si3g1NBkPm6iGjA== X-Google-Smtp-Source: AGHT+IGqddyuZsf2lqU9GYvb18Ekhsi9F0J5w06Piyn7GJ0ybWk9EIWRqw0vo48v2FRtPOO7suSW X-Received: by 2002:a17:902:d508:b0:1db:d3d7:88a7 with SMTP id b8-20020a170902d50800b001dbd3d788a7mr12450099plg.49.1708558769714; Wed, 21 Feb 2024 15:39:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708558769; cv=pass; d=google.com; s=arc-20160816; b=KX06tOchojSwj+OxcGRss+R0mbvYOFFxwGcLzSsTTNaW/MiiHL2MoSo0lpvCo1oVvs yVN8oUSCMD/1/3qoBHXzQQRhZHlf61GJBm3eo4IbbavWHWjap9UsrtprAM3eBH5tyWeG uTLV1rM7bnDecUEdRzLzwt//Ww2PHCFa5/5lhJ/sUdysLCtrtybvorRxgY9Hnuf7ybqf +SKAXm4EV4RBZU0a/oPmRVmGdd2qp11C5lX6Gs3O6ZROsEuNG0BYCKWe0Q1AlzWEJ7H1 cSG/iGsIiN+L/u9IO8UO4Qh3wuPmgZzKdOSd4ihi73bOLlW8selVLQuSEcMGSpjFjmY2 /6cg== 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=qdOxMAkyl5yi4MjXJFORjz39p90zOjZ6/27YgpZJWJY=; fh=/ABh5R9FVXrWRj7J9Qw3qrsQk+YtFHB8+P9pX2p9tUA=; b=gvlZb1pF/vt08DPvAPQi7CsV9zfqWV0JaP+YHMESZO1HwimNclBsmZ6QMirnI+KJj2 9wDTDQOAQ+OU4dUoy/9VhCbYrRonRCClGygwBFCvPO0YTXrFqHpzmQ58p6SCdNlmpHwQ hLmTPNt+fswoSfPiPtDOj9IJ4wyKdEwPZHQ1orDhGKKfPWnTMWorgK6qHZnvizR8pzX0 HoZqhc59D96AgjlC9qiiLpwrml4Tzd/VAWa9/goVt8F5qMwjZFMTtmfi30ioBGfCtG0E lqO0lsB7XCk+KmnJa9ZzvmZ5xe9SXcQJnizsghAbjJrkWXCca7JeR6RG1D9BAiB0L0Es hSuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=YPmVQ38K; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-75667-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75667-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id t3-20020a170902e84300b001d8a955d000si9388987plg.355.2024.02.21.15.39.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:39:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75667-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=YPmVQ38K; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-75667-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75667-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2E34CB21BBC for ; Wed, 21 Feb 2024 23:39:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 804C612D76D; Wed, 21 Feb 2024 23:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="YPmVQ38K" Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 BA8DC12AAD3 for ; Wed, 21 Feb 2024 23:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708558726; cv=none; b=Q7p07lK/GSlXo+27vtMrza6YLnk25DNV5cC4YFS76ealbmJxtpmO8hA47xVynOU5O6GCN2IBzXDXK7wT+EsXoAIla/fDamgAnbNHG90tKxnO5pS4I2x6GUigWCVKEx783Al9BalzF7r+QeH+cQhhX1RdrU9/gtsCLegA7OK2V0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708558726; c=relaxed/simple; bh=VbnWhAoLr3EeawQyolNDrQRXZNQkuXxI4yM52Iy8tIc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DFIEuG8fn9J7u3RSCfhTrbPmIfVNUHrF7YD+TkA9D5TxRirnUFKuojnnjUvhZRuxDKQ9sxNv4OkDvZZ4MlmF5/Az90u4P1pa6vwCKZRWv7Hp7em7Z3PsY65zIPXD39ExbkMx6j8WaeuNOkqD/s89gNZaTQ2fWUCBAEn2Tw61Gwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=YPmVQ38K; arc=none smtp.client-ip=209.85.219.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dcc4de7d901so6501214276.0 for ; Wed, 21 Feb 2024 15:38:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1708558724; x=1709163524; 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=qdOxMAkyl5yi4MjXJFORjz39p90zOjZ6/27YgpZJWJY=; b=YPmVQ38KfNBCioWnQH9i31aCO3qWe8g4FexNNDFGDhqNeUuG3XWPmFpEmA9awwJb5A XJMx1A4m8+BVZ1p3XAzZC0zKg0x2+yDBARbViUOghFqUGf+dz8CsnJ5TtGF1E2scHF+n V6duZxQp4Ar9bMK4gSSNOGSTRmg+5RW72XtCgnbZaFQ2Fdd7MiWjHHmP4E3GtBuFibTP IgYgbe2K/n8oF+Bbf6blxarTZldQ732ran3ZxPn05Tb9kRx/ux++hkqS0FRC2yAvwcXG pXLxyhQUGJkLQbYP71i9C14lJBPG5F27nJWtaJSiNcmk2DhBaP2K5piPo2wLFuE4tLYA p1IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708558724; x=1709163524; 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=qdOxMAkyl5yi4MjXJFORjz39p90zOjZ6/27YgpZJWJY=; b=JOt4paojmxgK1JPbuUArPRHply9nXx5MY2+3A1qS8N0Iz9COfjeeYMQnfRcyPPooMC 1t+vzzqXOObeTHAOWludfQbdprvMbw9kEvGTwfvN/1DN5DebKuX4dM+2UdUvfhtMJCUA TWvj96nnXxJrsx1aclJ5Z/8hmMSiI5OCqzhRO/x6x12paFyzBC5K2qvB/dzx5qcCZ8n8 sjU1eYj7MrXcO8ZydKwuIuj/Mnvl8ay1ctSTaOXylMFDj6+rIoeRA7DCNmLE6OjIxSv2 tkYD/CL5ZnnJDHdMFY0G+BVwxillGe/odER1k/i1t98703fPGgMrIhVshqkYsz7m+AYi eJkg== X-Forwarded-Encrypted: i=1; AJvYcCXmSnYWjPFxK9iGBcXMo/elHc9zXLxfOa7osUcEoueCwuz0N210xGyktUXeLh0xiBowquQiMExwkhb4+QLmitKzZ0H20TRqv5saerIm X-Gm-Message-State: AOJu0YzN/aMRif2WjXJLbeUotEVil27FKOPrJrNVNiSWp9R80YZ98rEC /sjIbfCURRgOaeEoOznwaVTj9+4XaftCPMEyRxioAcjNjlEBniZb9QQVUnldtGqb2qTuSlF39PP kyYE/nLByEOGsj7AyNpBjgn6VExFYNCRh9v9P X-Received: by 2002:a5b:c85:0:b0:dc6:d2d3:a57c with SMTP id i5-20020a5b0c85000000b00dc6d2d3a57cmr742866ybq.59.1708558723714; Wed, 21 Feb 2024 15:38:43 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240221-idmap-fscap-refactor-v2-0-3039364623bd@kernel.org> <20240221-idmap-fscap-refactor-v2-12-3039364623bd@kernel.org> In-Reply-To: <20240221-idmap-fscap-refactor-v2-12-3039364623bd@kernel.org> From: Paul Moore Date: Wed, 21 Feb 2024 18:38:33 -0500 Message-ID: Subject: Re: [PATCH v2 12/25] selinux: add hooks for fscaps operations To: "Seth Forshee (DigitalOcean)" Cc: Christian Brauner , Serge Hallyn , Eric Paris , James Morris , Alexander Viro , Jan Kara , Stephen Smalley , Ondrej Mosnacek , Casey Schaufler , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Miklos Szeredi , Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, audit@vger.kernel.org, selinux@vger.kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-unionfs@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 21, 2024 at 4:25=E2=80=AFPM Seth Forshee (DigitalOcean) wrote: > > Add hooks for set/get/remove fscaps operations which perform the same > checks as the xattr hooks would have done for XATTR_NAME_CAPS. > > Signed-off-by: Seth Forshee (DigitalOcean) > --- > security/selinux/hooks.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > index a6bf90ace84c..da129a387b34 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -3367,6 +3367,29 @@ static int selinux_inode_removexattr(struct mnt_id= map *idmap, > return -EACCES; > } > > +static int selinux_inode_set_fscaps(struct mnt_idmap *idmap, > + struct dentry *dentry, > + const struct vfs_caps *caps, int flag= s) > +{ > + return dentry_has_perm(current_cred(), dentry, FILE__SETATTR); > +} The selinux_inode_setxattr() code also has a cap_inode_setxattr() check which is missing here. Unless you are handling this somewhere else, I would expect the function above to look similar to selinux_inode_remove_fscaps(), but obviously tweaked for setting the fscaps and not removing them. > +static int selinux_inode_get_fscaps(struct mnt_idmap *idmap, > + struct dentry *dentry) > +{ > + return dentry_has_perm(current_cred(), dentry, FILE__GETATTR); > +} > + > +static int selinux_inode_remove_fscaps(struct mnt_idmap *idmap, > + struct dentry *dentry) > +{ > + int rc =3D cap_inode_removexattr(idmap, dentry, XATTR_NAME_CAPS); > + if (rc) > + return rc; > + > + return dentry_has_perm(current_cred(), dentry, FILE__SETATTR); > +} > + > static int selinux_path_notify(const struct path *path, u64 mask, > unsigned int obj_type) > { > @@ -7165,6 +7188,9 @@ static struct security_hook_list selinux_hooks[] __= ro_after_init =3D { > LSM_HOOK_INIT(inode_set_acl, selinux_inode_set_acl), > LSM_HOOK_INIT(inode_get_acl, selinux_inode_get_acl), > LSM_HOOK_INIT(inode_remove_acl, selinux_inode_remove_acl), > + LSM_HOOK_INIT(inode_set_fscaps, selinux_inode_set_fscaps), > + LSM_HOOK_INIT(inode_get_fscaps, selinux_inode_get_fscaps), > + LSM_HOOK_INIT(inode_remove_fscaps, selinux_inode_remove_fscaps), > LSM_HOOK_INIT(inode_getsecurity, selinux_inode_getsecurity), > LSM_HOOK_INIT(inode_setsecurity, selinux_inode_setsecurity), > LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity), > > -- > 2.43.0 --=20 paul-moore.com