Skip to contentSkip to conversation

bpf: Change inode_storage's lookup_elem return value from NULL to -EBADF.

PATCH Applied Tal Lossos 4 participants 4 messages Mar 7, 2021 – Mar 8, 2021 BPF

lore
Share & tools
lore

Tal Lossos

author
#0 lore raw

PATCH v2 1/1 bpf: Change inode_storage's lookup_elem return value from NULL to -EBADF.

bpf_fd_inode_storage_lookup_elem returned NULL when getting a bad FD, which caused -ENOENT in bpf_map_copy_value.
EBADF is better than ENOENT for a bad FD behaviour.

The patch was partially contributed by CyberArk Software, Inc.

---
 kernel/bpf/bpf_inode_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/bpf_inode_storage.c +1 -1
index da753721457c..2921ca39a93e 100644
@@ -109,7 +109,7 @@ static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
 	fd = *(int *)key;
 	f = fget_raw(fd);
 	if (!f)
-		return NULL;
+		return ERR_PTR(-EBADF);
 
 	sdata = inode_storage_lookup(f->f_inode, map, true);
 	fput(f);
Signature · 1 line
2.27.0
Acked-by
#2 lore raw
Quoted 8 lines · Yonghong Song
Quoted 4 lines · Tal Lossos

bpf_fd_inode_storage_lookup_elem returned NULL when getting a bad FD, which caused -ENOENT in bpf_map_copy_value.
EBADF is better than ENOENT for a bad FD behaviour.

Quoted 5 lines
Quoted 3 lines

The patch was partially contributed by CyberArk Software, Inc.

Thanks this makes sense and is consistent with sk_storage (which uses sockfd_lookup) and task_storage (which uses pidfd_get_pid) which return an -EBADF as well.

#3 lore raw
In reply to Tal Lossos
This patch was applied to bpf/bpf.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf.git (refs/heads/master):

Quoted 9 lines · On Sun, 7 Mar 2021 14:09:48 +0200 you wrote:

bpf_fd_inode_storage_lookup_elem returned NULL when getting a bad FD, which caused -ENOENT in bpf_map_copy_value.
EBADF is better than ENOENT for a bad FD behaviour.

The patch was partially contributed by CyberArk Software, Inc.

[...]

Here is the summary with links:
- [bpf-next,v2] bpf: Change inode_storage's lookup_elem return value from NULL to -EBADF.

    https://git.kernel.org/bpf/bpf/c/769c18b254ca

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html