Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1111683rdb; Fri, 22 Dec 2023 15:40:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM/pxP7UvGSnGnL+mmPURohYs9mxaesYuSXOqkrf0rQfWTagEfcMK24kyMzGVcmP2Dv1vJ X-Received: by 2002:ad4:5949:0:b0:67e:e561:1664 with SMTP id eo9-20020ad45949000000b0067ee5611664mr3268180qvb.101.1703288418860; Fri, 22 Dec 2023 15:40:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703288418; cv=none; d=google.com; s=arc-20160816; b=Y+LaTOLD6CnL+e7f2gpcLbAaDZdxBFnz5JWGqiKkZaTSIhDs25FPt73LLN7NcGRHpP Yz9ZIFBpnm7lPZUW+Csxe0e2OFUH7l4zXybW9rq2KkTCQyghH7MRhpLekwWRd55vr5HF pvqNwom5gyzXTilTBDYJxDvpR0GSmRPoZgHQq0uVc/lVfmHIJ87Z9rsYlf3QLpRkDJ8u +hD3Vqs8CovkF9B8LDOuGQKS2qabTFGZZZnqcpvQXZ6E8GMI4PskBx0ZDLpPjbPGNNeE dbXgV+Jip8Bs2TquG1k274b0brkK7D8ZnZ9TMU89l3JhNViU1t0C5DhjhkBL6pIM7deq 1cYg== ARC-Message-Signature: i=1; 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=xtZ7DoTLW1exe07faZsWlns7AQkFSE4d8R8G8FL+W54=; fh=aBxyFquevsK7ZWnPS36JWHLWoBLG5AyTokHPpyLsw38=; b=yfJJ5PoiCy/sVk51fhX9lCpGNDr6bVB36uUwPFUQ51wyYOhgg0iTsBQXN8Ztt5hBTL bDwluhm6DHwvV8xIvD8rDvhkFyKQUZbAfYcp0c2nOiEQ5Rf9vus3cjmjabQ9nIQM3sNs 3FWAVukfeAPd+bahxGmzJHWTtlwRmLUr4/yTnIKKKWfO4/GeuvhyCynZuV9oVVcqEh3h a+0RgoxhBfiRnZKEouCSHZ6PwXx9X31HUVrn6Ao2OG3A2a/Dh5rCDn8MtozJIJCHHCnf wqP3p9xZpenD0JSrJCi+y2IyuH3ijg3mErcibheHrqLKYRyYJ0NzynIM2zNqV6VjJiT4 C3bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=BhX1fWLh; spf=pass (google.com: domain of linux-kernel+bounces-10121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10121-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m4-20020a05620a220400b007812e5a9151si1922547qkh.549.2023.12.22.15.40.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:40:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=BhX1fWLh; spf=pass (google.com: domain of linux-kernel+bounces-10121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10121-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 794331C2225D for ; Fri, 22 Dec 2023 23:40:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D771935EF4; Fri, 22 Dec 2023 23:40:07 +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="BhX1fWLh" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 8D81B341B1 for ; Fri, 22 Dec 2023 23:40:05 +0000 (UTC) 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-f182.google.com with SMTP id 3f1490d57ef6-da7ea62e76cso2278219276.3 for ; Fri, 22 Dec 2023 15:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1703288404; x=1703893204; 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=xtZ7DoTLW1exe07faZsWlns7AQkFSE4d8R8G8FL+W54=; b=BhX1fWLha23oq5ZIgDUjH9vv1lGlwIVCi3GLw0JwRo0aG7XwYZv85+77LskHdlQo1D bwsIkS7xpvTFw8oAdgSv29mGaUrAvP5Wx/261gIhM/6zMeo8k42oB/b9HryLnDsJE8Cx GUytWtYtsKa24oI4PUJff9pGZFK90skjIWVkJFW+GNQC5Y5dcuxibGnU6oiPOsX5oH/h Y0L+oVrW5PSmYh7FetSM7oaX5V8tDNInJlKAZiXQBMZ6OpYSMCX46FBWXE+jLXKCAYan dodQ1jF0leo+SSkWoD+CU1evbVt2XuUFoQbJacILMO5Q4u2CKs4FahH5T3D6g3H192Ug jr5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703288404; x=1703893204; 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=xtZ7DoTLW1exe07faZsWlns7AQkFSE4d8R8G8FL+W54=; b=Cj/+NdbRH0elq3eW7HTXPmt31aH9tFqqNEwbozOMsWTZAQ6n7GiHU4jXAiojR3EwYW tsDyriTxA6xgi2yXcvYmBcrCucJsjVHWFd6/+RRkEvrdckhFJ9A/wy/Efpp2anBZze6H XB9EQ4RXPJbBpozIA+i2L0tTBVeMyABAnpd3f1Ud9zHg8KaL3iIJxz7JT8ZuvKVxz47K 92N7juGVS3OhXQgUZdRaqommKQgCFWf+cGrpU0DmnzV6qokAhDYtQ8ajUPCUhWkCVVR1 UeDNNTf+E7cjoHLMS4IqLfykvfdik+/6IG+dPchFngv4oFG8lNUygwXm/TRa0BPn5UaA FcfA== X-Gm-Message-State: AOJu0YxOaTXP+3XVqegycJ3LmPIibMXLpxcR1GNEOofI0fjZ7zXVfEY7 7MpJXtGAC5ntVSh4KRGUhfRK5Kkc5wzD7PJnGF7f2vZgAeO9 X-Received: by 2002:a25:db4b:0:b0:db7:dacf:ed65 with SMTP id g72-20020a25db4b000000b00db7dacfed65mr1422088ybf.70.1703288404352; Fri, 22 Dec 2023 15:40:04 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231213143813.6818-1-michael.weiss@aisec.fraunhofer.de> <20231213143813.6818-4-michael.weiss@aisec.fraunhofer.de> <20231215-golfanlage-beirren-f304f9dafaca@brauner> <61b39199-022d-4fd8-a7bf-158ee37b3c08@aisec.fraunhofer.de> <20231215-kubikmeter-aufsagen-62bf8d4e3d75@brauner> <20231216-vorrecht-anrief-b096fa50b3f7@brauner> <20231218-chipsatz-abfangen-d62626dfb9e2@brauner> In-Reply-To: <20231218-chipsatz-abfangen-d62626dfb9e2@brauner> From: Paul Moore Date: Fri, 22 Dec 2023 18:39:53 -0500 Message-ID: Subject: Re: [RFC PATCH v3 3/3] devguard: added device guard for mknod in non-initial userns To: Christian Brauner Cc: Alexei Starovoitov , =?UTF-8?Q?Michael_Wei=C3=9F?= , Alexander Mikhalitsyn , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Quentin Monnet , Alexander Viro , Miklos Szeredi , Amir Goldstein , "Serge E. Hallyn" , bpf , LKML , Linux-Fsdevel , LSM List , gyroidos@aisec.fraunhofer.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 7:30=E2=80=AFAM Christian Brauner wrote: > I'm not generally opposed to kfuncs ofc but here it just seems a bit > pointless. What we want is to keep SB_I_{NODEV,MANAGED_DEVICES} confined > to alloc_super(). The only central place it's raised where we control > all locking and logic. So it doesn't even have to appear in any > security_*() hooks. > > diff --git a/security/security.c b/security/security.c > index 088a79c35c26..bf440d15615d 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1221,6 +1221,33 @@ int security_sb_alloc(struct super_block *sb) > return rc; > } > > +/* > + * security_sb_device_access() - Let LSMs handle device access > + * @sb: filesystem superblock > + * > + * Let an LSM take over device access management for this superblock. > + * > + * Return: Returns 1 if LSMs handle device access, 0 if none does and -E= RRNO on > + * failure. > + */ > +int security_sb_device_access(struct super_block *sb) > +{ > + int thisrc; > + int rc =3D LSM_RET_DEFAULT(sb_device_access); > + struct security_hook_list *hp; > + > + hlist_for_each_entry(hp, &security_hook_heads.sb_device_access, l= ist) { > + thisrc =3D hp->hook.sb_device_access(sb); > + if (thisrc < 0) > + return thisrc; > + /* At least one LSM claimed device access management. */ > + if (thisrc =3D=3D 1) > + rc =3D 1; > + } > + > + return rc; > +} I worry that this hook, and the way it is plumbed into alloc_super() below, brings us back to the problem of authoritative LSM hooks which is something I can't support at this point in time. The same can be said for a LSM directly flipping bits in the superblock struct. The LSM should not grant any additional privilege, either directly in the LSM code, or indirectly via the caller; the LSM should only restrict operations which would have otherwise been allowed. The LSM should also refrain from modifying any kernel data structures that do not belong directly to the LSM. A LSM caller may modify kernel data structures that it owns based on the result of the LSM hook, so long as those modifications do not grant additional privilege as described above. > diff --git a/fs/super.c b/fs/super.c > index 076392396e72..2295c0f76e56 100644 > --- a/fs/super.c > +++ b/fs/super.c > @@ -325,7 +325,7 @@ static struct super_block *alloc_super(struct file_sy= stem_type *type, int flags, > { > struct super_block *s =3D kzalloc(sizeof(struct super_block), GF= P_USER); > static const struct super_operations default_op; > - int i; > + int err, i; > > if (!s) > return NULL; > @@ -362,8 +362,16 @@ static struct super_block *alloc_super(struct file_s= ystem_type *type, int flags, > } > s->s_bdi =3D &noop_backing_dev_info; > s->s_flags =3D flags; > - if (s->s_user_ns !=3D &init_user_ns) > + > + err =3D security_sb_device_access(s); > + if (err < 0) > + goto fail; > + > + if (err) > + s->s_iflags |=3D SB_I_MANAGED_DEVICES; > + else if (s->s_user_ns !=3D &init_user_ns) > s->s_iflags |=3D SB_I_NODEV; > + > INIT_HLIST_NODE(&s->s_instances); > INIT_HLIST_BL_HEAD(&s->s_roots); > mutex_init(&s->s_sync_lock); --=20 paul-moore.com