From patchwork Fri Mar 29 01:53:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 13609884 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 A997C39AFD for ; Fri, 29 Mar 2024 01:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677258; cv=none; b=tSRPM9qkg9V0/Jns9U+7FjxvCg2kwTIBDm6LMpW4IQwVDI0vCrOiy2ey8wrv4+3G23opGAyDQZPSYkM8bVp+SZNn5cP1xsR9ZFwOWq044tkbbOJke458xaqjRI/vKJJG3AIBXJo4E8iAIA64U0foHsJYYNSZsh+4DRVcb3Iz20I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677258; c=relaxed/simple; bh=tFmf24Mjc0l+J1FvLtlzPLbHQwNkOVITHodym4M2p8g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WObKOj1Hw4oCDFo8Z0H4v/LKhCJ6HuMqKdwHHHhDvh8TSq228T2zgGILg4Fj55rTGNlvU8hRIjuh/gFNi7maVgvC+Kq5hRx3FiVY5pHi3R/tO7033fZ5xFa6I/Bp5Hvrg6zPcSV4qLnZqfCGln/NYNMC2t+N+a8tiwlMdboRruI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YmargXJs; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YmargXJs" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60ff1816749so27306067b3.3 for ; Thu, 28 Mar 2024 18:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711677255; x=1712282055; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eeuNGA+8CuovI+htgf5CrcA9lpm9o2FtGFCkGxKFo9c=; b=YmargXJsKh02pEkO2JoheAf/ikD8SSfSQ51Blbp5F8DAr5dPQ/rnMKP/5o8iF8+jRv 7mFRutAXe0FIFDAAWby/UVsz8XTcP8AjpQ1LOwhtLzjPdinT+jauAaBhUymSJOZCvMqb 1FNIFM2djvTlX3jj3gGgSa9fEPCY0SOrTP9MwQNmkjmmhOqmIqFE4huYbJcpZIy/AAbX 9FzZUvtp61PhBrXzdY1GPSDadvIX1nht7opJRX0OvTXnhhdTCX98ZJvI8MWkL1VK3fTz xzLBQzXRYxFaR8Yp+Kti9kNO2amKVzfC13R7/c/a1EWwZfJzQS8S9SrE7QekU068oUGm RRww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711677255; x=1712282055; 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=eeuNGA+8CuovI+htgf5CrcA9lpm9o2FtGFCkGxKFo9c=; b=WIBQtuljCE9dzaaGx/m53nrxYMsvYkhP7DpkDnsV7p7O1mmqO3VTlSHijjfXuyxmu2 5xR7QS3fknfB/E+7OJbrAMQZBfuG6i5UTz7epMbnPg8XYLSfDsp1JBxS06GOhxXjXRxL HWVtArk/GvlI3RUc1dr/LppgsGKWlhO/bY4EhpEAI26cFyZ4nhT1BslP2fkCMoKyus02 ZNW5n1LamIYDFDaLzxPKOhqSv+zzpuYzGdL5XXfb2FceqH7X+EZt9Fvk5/zJM4Q5WwR2 lPacC9of8h4Qm2LxllALJB4te2CCOozeOZuhacz5OTH2qPUFeb1bPnWgRF1dB7zayVm+ yCzA== X-Forwarded-Encrypted: i=1; AJvYcCV7iwK8S9ObCO86mbTN4dIi+8uGEfiQOUR3l74tzrvlAy3LR7f/LriUzTaI9G8ywFXZmo0aIAtgicp0Mi76KUZEZt04 X-Gm-Message-State: AOJu0YxXaHvpWiu6TnBRAxZHjcwoxsxR2cTnaYowrA3pYpvd/Ap1gJgz +mYxJbnZJYNrxWqaMS1WQUeaA0tkZtOJauzDZBQIf+koGm6ZVOv9Fs4tL6TM+dctW598CbZ+XRq 5lw== X-Google-Smtp-Source: AGHT+IHRQU6ab0eRho+UjDvwkzeb9d7pS8VugdyuU3acPa0I9eBDEaOKo5pla1Pw5XzmlyStLuGkngRj8h4= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:fcce:d6ab:804c:b94b]) (user=drosen job=sendgmr) by 2002:a81:4e10:0:b0:611:5ca6:59c3 with SMTP id c16-20020a814e10000000b006115ca659c3mr248817ywb.6.1711677254863; Thu, 28 Mar 2024 18:54:14 -0700 (PDT) Date: Thu, 28 Mar 2024 18:53:22 -0700 In-Reply-To: <20240329015351.624249-1-drosen@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329015351.624249-1-drosen@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329015351.624249-8-drosen@google.com> Subject: [RFC PATCH v4 07/36] 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 , Eduard Zingerman , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , Christian Brauner , kernel-team@android.com, Daniel Rosenberg , Paul Lawrence X-Patchwork-State: RFC 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 14fcc2032764..a94d99ff9862 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -420,3 +420,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 6503c91886f6..8db6eb6a0848 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1563,6 +1563,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) @@ -1619,6 +1622,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 dd62e78e474c..08ee98b7bb95 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1439,6 +1439,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 @@ -1447,6 +1448,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);