Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp1106470rdb; Wed, 16 Aug 2023 01:39:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGB4tVsm+erdVBDo+0DIWlpAkUrBt8Ns3j5fyqOL25g+BHnMDNGhnIudRmyETCX1WP43X7B X-Received: by 2002:a05:6808:6382:b0:3a7:2690:94e0 with SMTP id ec2-20020a056808638200b003a7269094e0mr1636519oib.4.1692175144604; Wed, 16 Aug 2023 01:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692175144; cv=none; d=google.com; s=arc-20160816; b=nMDqbCB9QVhicaFV5uUovXte3bJReWb4hqT61X0siNWa7K6jp2hbFA9f/ums/YlTH6 9upimTDlb5HZxvRV+uPuS/fDJywPxgyQ8mmYCxMujoUwrpe6PH8ZuW35idzU3Emntm6/ eESSr7kEpj1HdNCJyH4sty+PgxO+H/5AaWPKuALBtmxY56Wih1vD5AYv3NZ+pjJusuOz CrsLmT96RPeMxWy7kc8rTkPnrYokqQ92BXWDmEfuyUoC++Z+h1deu7FEyrtHFa+LdZVB hcfgZQsZS+W77R8NkEch6bgL6930t8PyUQywXhxIZmd56rAZ8MK0M42qb/8S+8ZaSBC5 U/Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=J+l7RgOWc4acLo1SYyM1qk99KXs2xjckzvabDZ1tLYg=; fh=MFBxdLThvEbdDHzM1WUAzjiekCzLvoJ5dTCKcWYvZjo=; b=IcbA2fMPNwbJTKp57Cai85StHjOJ7PA5MRIL/VQjt5iPkrKbK+DrEZ/cK1y9jTZtri cYcdO1o+8VDYDTS5qxQ5NotEXXXxhG74BKjEcCzZWNdbqQIHDl9ykrf7FEUhGwE3ARxo s+HdZuqmhtLYgocIHcqOYeipBeINtxg8/6KRmLZm5MVeaN4arTP4/4agQ2RKrJUnRX2B d59wJJbQXIKNKfvBgjPAB1quFk6YYwUTkL+/Nf/m52scCZAo+kggDWpqUy3qfs5gZIe4 9lt8bAw8XzsMqmCmObTFR4Nf9vWGewwTmTPZR55+lHLtA80nw9xgp7oLgFYfae8el63Z 5BcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c5eMKzto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m1-20020a656a01000000b0056532fbe28csi11492766pgu.459.2023.08.16.01.38.48; Wed, 16 Aug 2023 01:39:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c5eMKzto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235819AbjHOJA5 (ORCPT + 99 others); Tue, 15 Aug 2023 05:00:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235938AbjHOI7b (ORCPT ); Tue, 15 Aug 2023 04:59:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B46AF1BC0; Tue, 15 Aug 2023 01:59:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4023263E2F; Tue, 15 Aug 2023 08:59:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97C15C433C7; Tue, 15 Aug 2023 08:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692089969; bh=MArXAIr8c9w9SGHAmRMmXFdx0pibI2BQaL9ZvGmfZ+k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=c5eMKztoKIGPUroWlu0kDWQckmc28nItr01rFT5I4CClgh1M1uBGGsZnH0LVIWtxQ qbyNyWmOigSmPPXS//NsFqZ9z6h+6rRzHjkCFmltOp/mkVdE2AzNOBZUgCaIrPJu+r t5DXUaKuPLwXWbvbt2oDhXLrx1ief2b1C0jrRI9DQ9WUBxNdcwtLDipJ3GH9bMJgQM fylZxEdJM8GgdaLe3wW0HTPWleupgJAT4B6d5eGuxRTVkc4uyMvaeRpJbJJjLfBl6M RiNcn4YA86xiFhW6ycuJCQ+Xt9h3rNTaqz3fqPDb+/mnBoD5TArukWBsYwS9HDsJJg Is5XzyeFf2jLA== Date: Tue, 15 Aug 2023 10:59:22 +0200 From: Christian Brauner To: Michael =?utf-8?B?V2Vpw58=?= Cc: 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 , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, gyroidos@aisec.fraunhofer.de Subject: Re: [PATCH RFC 1/4] bpf: add cgroup device guard to flag a cgroup device prog Message-ID: <20230815-feigling-kopfsache-56c2d31275bd@brauner> References: <20230814-devcg_guard-v1-0-654971ab88b1@aisec.fraunhofer.de> <20230814-devcg_guard-v1-1-654971ab88b1@aisec.fraunhofer.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230814-devcg_guard-v1-1-654971ab88b1@aisec.fraunhofer.de> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 14, 2023 at 04:26:09PM +0200, Michael Weiß wrote: > Introduce the BPF_F_CGROUP_DEVICE_GUARD flag for BPF_PROG_LOAD > which allows to set a cgroup device program to be a device guard. Currently we block access to devices unconditionally in may_open_dev(). Anything that's mounted by an unprivileged containers will get SB_I_NODEV set in s_i_flags. Then we currently mediate device access in: * inode_permission() -> devcgroup_inode_permission() * vfs_mknod() -> devcgroup_inode_mknod() * blkdev_get_by_dev() // sget()/sget_fc(), other ways to open block devices and friends -> devcgroup_check_permission() * drivers/gpu/drm/amd/amdkfd // weird restrictions on showing gpu info afaict -> devcgroup_check_permission() All your new flag does is to bypass that SB_I_NODEV check afaict and let it proceed to the devcgroup_*() checks for the vfs layer. But I don't get the semantics yet. Is that a flag which is set on BPF_PROG_TYPE_CGROUP_DEVICE programs or is that a flag on random bpf programs? It looks like it would be the latter but design-wise I would expect this to be a property of the device program itself.