Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6636575rdb; Fri, 15 Dec 2023 04:32:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9iUglPxy7ife4yoyxNGGFU8vtm4c6TJ7CIowFqJuOu/rxVFu7lAjHoDChQbpBwyHoTBbp X-Received: by 2002:a05:6214:27e9:b0:67f:1406:dad1 with SMTP id jt9-20020a05621427e900b0067f1406dad1mr2402422qvb.34.1702643532401; Fri, 15 Dec 2023 04:32:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702643532; cv=none; d=google.com; s=arc-20160816; b=t/ShW36QjtuoCJbq29GjMM/Ybk7xRpPYIlJ9nl6FRtAp017auayHiLFoD6anXNadgT RvRA+Wwzv1uxvAEpjiBZbI3X8kgCaxAPl3tZMmw/QwZbX15wWSADmGAh9tLXuHwwFGUf M/YIvww/g1Yv6FyeRhuBIDqCkz2CEto0XZxAVWfsK8o5n6AbvkuobXJGHYtgkG8/krEP in3ORzF1btG1iYAqSUVf/K5JndeBZxej2ukX83iAJ83Ty6Uhjp/innOVsDs4tnjLrBEj rt2h69bdmDRYDsF4mAhpEXBynkVDruxNs/XtYd6pHxgbkFDWWSSutoSuOnITs5X+Eftb TRyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=29d9vymd5/zG7LIqNvuBmpIWc2a3xEBXsXz1ZmW7Nws=; fh=+av8j8jihxQ6Y+D9CVV5wtJyJbApBTAbciGc4RkpZ9A=; b=AAvOkXtZrBiqYaCeuUrigbppTGY4Z4IXefV0faAQOBJOynZ/UCMTSlYOcoo6kPYhN7 RetgNS3MOuVdn9LmQ7W4U6W3uTzdTuFT6WGa7UJtbB4k6cEnw8TngC1/U2FBsaJRRtnv PfJM1UWxLjtw+m4zkAfGSz0oM/c4tdkNHnyhtGFiQkK5sWfopvwwjiENEriZqsWhaaCh 2s4rbXkHWMggG7b0lJ4q9GfDSwR+skNHSu7cEC2S/MRcTAr95VeGczY1z/QZ7DLraCku zMT4OOCWQbS/mMfTe3EV5z7vrxkW1iwFajbnMcinajtvyWOCtDzn7kUOtl+YxKo/D7tE mfmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fLWeqMrI; spf=pass (google.com: domain of linux-kernel+bounces-925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id du2-20020a05620a47c200b0077d5e6f7aaasi5312505qkb.253.2023.12.15.04.32.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 04:32:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-925-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=@kernel.org header.s=k20201202 header.b=fLWeqMrI; spf=pass (google.com: domain of linux-kernel+bounces-925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1C9C01C23532 for ; Fri, 15 Dec 2023 12:32:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81D182C868; Fri, 15 Dec 2023 12:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fLWeqMrI" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A21832D033; Fri, 15 Dec 2023 12:31:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BDD1C433C7; Fri, 15 Dec 2023 12:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702643502; bh=F2ajDU7FVMvzLFF89TySlMLk6Wm17ybM4bb/3tTycL4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fLWeqMrINDuf4fclsBa9vwJ3LVwgD8gZwJUzNMZAmMQw0OOq62kwBKytqminKjUPv KHUBcwnCONHfYXZBuIVONjo30VQ7p9m5QUGAdAdzxUlcV7bdkrk55xGQDf65yfJw6Z jcKABEYcIBxT+Ljw10Uu7TYsgEGhak+uvJ2Npicett7hvPGCgmVPn3TG/l5BIs8/mS 3qGXDoJQ/AdnwPaa5YYTa3giFDmQIutX5qUAXNlddr6ZvrelenQCJhScNBCfIhB5Go 5zJ1pFj3aGRJEejS61H6JkxF+vRaXFpUBwpdBXEge9czkeLn/alaLXqLxcbNuxtVHv W07Vz7GBxR7AQ== Date: Fri, 15 Dec 2023 13:31:32 +0100 From: Christian Brauner To: Michael =?utf-8?B?V2Vpw58=?= Cc: Alexander Mikhalitsyn , Alexei Starovoitov , Paul Moore , 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@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, gyroidos@aisec.fraunhofer.de Subject: Re: [RFC PATCH v3 3/3] devguard: added device guard for mknod in non-initial userns Message-ID: <20231215-golfanlage-beirren-f304f9dafaca@brauner> References: <20231213143813.6818-1-michael.weiss@aisec.fraunhofer.de> <20231213143813.6818-4-michael.weiss@aisec.fraunhofer.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231213143813.6818-4-michael.weiss@aisec.fraunhofer.de> On Wed, Dec 13, 2023 at 03:38:13PM +0100, Michael Weiß wrote: > devguard is a simple LSM to allow CAP_MKNOD in non-initial user > namespace in cooperation of an attached cgroup device program. We > just need to implement the security_inode_mknod() hook for this. > In the hook, we check if the current task is guarded by a device > cgroup using the lately introduced cgroup_bpf_current_enabled() > helper. If so, we strip out SB_I_NODEV from the super block. > > Access decisions to those device nodes are then guarded by existing > device cgroups mechanism. > > Signed-off-by: Michael Weiß > --- I think you misunderstood me... My point was that I believe you don't need an additional LSM at all and no additional LSM hook. But I might be wrong. Only a POC would show. Just write a bpf lsm program that strips SB_I_NODEV in the existing security_sb_set_mnt_opts() call which is guranteed to be called when a new superblock is created. Store your device access rules in a bpf map or in the sb->s_security blob (This is where I'm fuzzy and could use a bpf LSM expert's input.). Then make that bpf lsm program kick in everytime a security_inode_mknod() and security_file_open() is called and do device access management in there. Actually, you might need to add one hook when the actual device that's about to be opened is know. This should be where today the device access hooks are called. And then you should already be done with this. The only thing that you need is the capable check patch. You don't need that cgroup_bpf_current_enabled() per se. Device management could now be done per superblock, and not per task. IOW, you allowlist a bunch of devices that can be created and opened. Any task that passes basic permission checks and that passes the bpf lsm program may create device nodes. That's a way more natural device management model than making this a per cgroup thing. Though that could be implemented as well with this. I would try to write a bpf lsm program that does device access management with your capable() sysctl patch applied and see how far I get. I don't have the time otherwise I'd do it.