[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c2239508-6d00-4176-b0d6-3e07e06a367f@linux.dev>
Date: Tue, 12 Nov 2024 15:26:43 -0800
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Song Liu <song@...nel.org>
Cc: bpf@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-security-module@...r.kernel.org,
kernel-team@...a.com, andrii@...nel.org, eddyz87@...il.com, ast@...nel.org,
daniel@...earbox.net, viro@...iv.linux.org.uk, brauner@...nel.org,
jack@...e.cz, kpsingh@...nel.org, mattbobrowski@...gle.com,
amir73il@...il.com, repnop@...gle.com, jlayton@...nel.org,
josef@...icpanda.com, mic@...ikod.net, gnoack@...gle.com
Subject: Re: [PATCH v2 bpf-next 3/4] bpf: Add recursion prevention logic for
inode storage
On 11/12/24 12:36 AM, Song Liu wrote:
> +static void *__bpf_inode_storage_get(struct bpf_map *map, struct inode *inode,
> + void *value, u64 flags, gfp_t gfp_flags, bool nobusy)
> {
> struct bpf_local_storage_data *sdata;
>
> - WARN_ON_ONCE(!bpf_rcu_lock_held());
> - if (flags & ~(BPF_LOCAL_STORAGE_GET_F_CREATE))
> - return (unsigned long)NULL;
> -
> + /* explicitly check that the inode not NULL */
> if (!inode)
> - return (unsigned long)NULL;
> + return NULL;
>
> sdata = inode_storage_lookup(inode, map, true);
s/true/nobusy/
> if (sdata)
> - return (unsigned long)sdata->data;
> + return sdata->data;
>
> - /* This helper must only called from where the inode is guaranteed
> - * to have a refcount and cannot be freed.
> - */
> - if (flags & BPF_LOCAL_STORAGE_GET_F_CREATE) {
> + /* only allocate new storage, when the inode is refcounted */
> + if (atomic_read(&inode->i_count) &&
> + flags & BPF_LOCAL_STORAGE_GET_F_CREATE) {
(flags & BPF_LOCAL_STORAGE_GET_F_CREATE) && nobusy) {
> sdata = bpf_local_storage_update(
> inode, (struct bpf_local_storage_map *)map, value,
> BPF_NOEXIST, false, gfp_flags);
> - return IS_ERR(sdata) ? (unsigned long)NULL :
> - (unsigned long)sdata->data;
> + return IS_ERR(sdata) ? NULL : sdata->data;
> }
>
> - return (unsigned long)NULL;
> + return NULL;
> +}
Powered by blists - more mailing lists