Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4755729rwe; Mon, 17 Apr 2023 18:43:12 -0700 (PDT) X-Google-Smtp-Source: AKy350YYrBIub+8cm12NtkxUscjjaf9Olx6BecMpTCPFhQaSd7pGLWX2Sk3fy0Gp50GEELIUhIJQ X-Received: by 2002:a05:6a00:2d15:b0:63d:259b:b5ca with SMTP id fa21-20020a056a002d1500b0063d259bb5camr5423653pfb.11.1681782191698; Mon, 17 Apr 2023 18:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782191; cv=none; d=google.com; s=arc-20160816; b=eyj2gO62Z3enIbuWEItknuDI46LxlZXgnBlLN3tly3C2IonRuq4VHm+gGbgy7BfUdR UydW7O5GnLM/o9COKsdmlFUy208UCNP54LK6MKgBXyel626sg1Df8toZVXOh6dUP4FpI rTYMu+OeMijjDT8+MyiAk5pJUJAhBYW3W2JMh9QwqE+opLzM9eFg+Ixcs8TPtJbTckzn R7/RbNwXyZUPDg18O1rAgzVoIXS4vBVCXIfVDZtFUKK0Q8hv6xCXUe3kzMGKBccDZhJ/ k4k6eelsuLkrw+a1hcu4yd92i88hKxB+yEgQqL40txlZd5JdyolYpypxpAZ3EpeiZ6AL zFwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=1Zzn8o1i1Qipa77dzB0ZPLXp5K2/As2sG8h87DoyjGM=; b=Q+bXv91SwLfeDuGmACtMi82JXwd2l2YLL38wrJVFgSsn5tK/Ie5pEG2jQwHvbcI+Im BQk20q8T6RKxv0fmhRyjScVyY53d+LWek2ix6VEWV2HJd5uiiN/I9/IgSIJmqx9ofLWs 6S6X0YWnBteKYpfp7QBNo9W6SqqepZy4Ef93La7m7QsM0aQ73cbTf/RUcwCyNSakkUVG pWMS5TAxKu2ZieXzaDaLED4UDFHpC82E0Gluj5SrPp9fjFvlu3S2CgLKazQgAAgLxSGp ECTxjrk9MxC4grKiIfskOvESzZoHJbKBwre6Xu4/UCqNnFCL1YljeB0/BPoSElaXutxQ 2rJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2+I98OIJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020aa7842e000000b0063b7e177fc3si7132526pfn.165.2023.04.17.18.42.56; Mon, 17 Apr 2023 18:43:11 -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=@google.com header.s=20221208 header.b=2+I98OIJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230518AbjDRBmd (ORCPT + 99 others); Mon, 17 Apr 2023 21:42:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbjDRBl6 (ORCPT ); Mon, 17 Apr 2023 21:41:58 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F425659F for ; Mon, 17 Apr 2023 18:41:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 188-20020a250ac5000000b00b9265c9a5e9so2183164ybk.11 for ; Mon, 17 Apr 2023 18:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782075; x=1684374075; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1Zzn8o1i1Qipa77dzB0ZPLXp5K2/As2sG8h87DoyjGM=; b=2+I98OIJuVmlxxZnL112cFQtwT3jCQDjIow9U7tinQ0J7PnT7CW2nk5rnzuaqyfrh7 t3DlfVAZR6sD5E+Luhvth8wbofyEZeHmBpkUkBocSpBEVttlXwuggShqUO9kj7Yq0/h/ aX7QFH/O8g9rnwLpOW9lAXc/V85QKHAhuJlpvE7i1s3Gysd2bhwkmvNvqQ40s9IHS+fW iwFwXKp/SUQPTFNVB9+Xbi1KWg/VuO0heZfOSN2cvyCPhvHY7TR+CKbNpElBlFthzn2Y NCkq3jwcH9x/45VO8uba3X5M5Kc8fLUu98eMXLHD5qQZ70F2CYgsgu/Pb70DPzEmoCIC +4Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782075; x=1684374075; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1Zzn8o1i1Qipa77dzB0ZPLXp5K2/As2sG8h87DoyjGM=; b=bD75M60ySuLD9mypLf2MES9z7VbDqFfxlcYNDondj8yseEWVn4Ym2J+KU1ZcRr5STw qvquhfEYxYaJdzvoEbzDWuE7EnQSNHapw1D6qxBD2GeCzvQct1MJLh7HcTzLijard071 GSrvz+EtE2fyKtnn1/6u8F/EDGvInJvm3vBEhjXaJXKyAC0pXIYCGXaQk8hv8ZN2wNP0 h1DmcObx5kvKTNaY+ndaP75wLr5/0/zx8KUnHyyuA1iJid7RhSZ2WvRJ7NiuP61a3d5D nLkLMcfVqJbhdDfIOhg4zfPUX/2ySowZU4WCoMhn94TVG9kyTBXWkdcAnp5tyf2iG8KM x7qA== X-Gm-Message-State: AAQBX9cFikqnJBOM2ZdS/yNKydsLWBoXUQ4abZ6CUssXmTZSfsXcDXxp Ijy/xUdlL4+E3g4vSxUdXA6WZtJtkjI= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a25:74d0:0:b0:b92:25a0:90d with SMTP id p199-20020a2574d0000000b00b9225a0090dmr5872731ybc.0.1681782075783; Mon, 17 Apr 2023 18:41:15 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:11 -0700 In-Reply-To: <20230418014037.2412394-1-drosen@google.com> Mime-Version: 1.0 References: <20230418014037.2412394-1-drosen@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418014037.2412394-12-drosen@google.com> Subject: [RFC PATCH v3 11/37] fuse-bpf: Add support for access From: Daniel Rosenberg To: Miklos Szeredi , bpf@vger.kernel.org, Alexei Starovoitov Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , kernel-team@android.com, Daniel Rosenberg , Paul Lawrence Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 This adds backing support for FUSE_ACCESS Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/dir.c | 6 ++++++ fs/fuse/fuse_i.h | 6 ++++++ 3 files changed, 59 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 3d895957b5ce..e42622584037 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -417,3 +417,50 @@ int fuse_revalidate_backing(struct dentry *entry, unsigned int flags) return backing_entry->d_op->d_revalidate(backing_entry, flags); return 1; } + +static int fuse_access_initialize_in(struct bpf_fuse_args *fa, struct fuse_access_in *in, + struct inode *inode, int mask) +{ + *in = (struct fuse_access_in) { + .mask = mask, + }; + + *fa = (struct bpf_fuse_args) { + .info = (struct bpf_fuse_meta_info) { + .opcode = FUSE_ACCESS, + .nodeid = get_node_id(inode), + }, + .in_numargs = 1, + .in_args[0].size = sizeof(*in), + .in_args[0].value = in, + }; + + return 0; +} + +static int fuse_access_initialize_out(struct bpf_fuse_args *fa, struct fuse_access_in *in, + struct inode *inode, int mask) +{ + return 0; +} + +static int fuse_access_backing(struct bpf_fuse_args *fa, int *out, struct inode *inode, int mask) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + const struct fuse_access_in *fai = fa->in_args[0].value; + + *out = inode_permission(&nop_mnt_idmap, fi->backing_inode, fai->mask); + return 0; +} + +static int fuse_access_finalize(struct bpf_fuse_args *fa, int *out, struct inode *inode, int mask) +{ + return 0; +} + +int fuse_bpf_access(int *out, struct inode *inode, int mask) +{ + return bpf_fuse_backing(inode, struct fuse_access_in, out, + fuse_access_initialize_in, fuse_access_initialize_out, + fuse_access_backing, fuse_access_finalize, inode, mask); +} diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 73ebe3498fb9..535e6cf9e970 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1439,6 +1439,9 @@ static int fuse_access(struct inode *inode, int mask) struct fuse_access_in inarg; int err; + if (fuse_bpf_access(&err, inode, mask)) + return err; + BUG_ON(mask & MAY_NOT_BLOCK); if (fm->fc->no_access) @@ -1495,6 +1498,9 @@ static int fuse_permission(struct mnt_idmap *idmap, if (!fuse_allow_current_process(fc)) return -EACCES; + if (fuse_bpf_access(&err, inode, mask)) + return err; + /* * If attributes are needed, refresh them before proceeding */ diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 39a9fdf2a752..cb166168f9c2 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1406,6 +1406,7 @@ int parse_fuse_bpf_entry(struct fuse_bpf_entry *fbe, int num_entries); #ifdef CONFIG_FUSE_BPF int fuse_bpf_lookup(struct dentry **out, struct inode *dir, struct dentry *entry, unsigned int flags); +int fuse_bpf_access(int *out, struct inode *inode, int mask); #else @@ -1414,6 +1415,11 @@ static inline int fuse_bpf_lookup(struct dentry **out, struct inode *dir, struct return 0; } +static inline int fuse_bpf_access(int *out, struct inode *inode, int mask) +{ + return 0; +} + #endif // CONFIG_FUSE_BPF int fuse_handle_backing(struct fuse_bpf_entry *feb, struct path *backing_path); -- 2.40.0.634.g4ca3ef3211-goog