diff mbox series

[bpf] bpf: relax inode permission check for retrieving bpf program

Message ID 20190515024257.36838-1-fengc@google.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf] bpf: relax inode permission check for retrieving bpf program | expand

Commit Message

Chenbo Feng May 15, 2019, 2:42 a.m. UTC
For iptable module to load a bpf program from a pinned location, it
only retrieve a loaded program and cannot change the program content so
requiring a write permission for it might not be necessary.
Also when adding or removing an unrelated iptable rule, it might need to
flush and reload the xt_bpf related rules as well and triggers the inode
permission check. It might be better to remove the write premission
check for the inode so we won't need to grant write access to all the
processes that flush and restore iptables rules.

Signed-off-by: Chenbo Feng <fengc@google.com>
---
 kernel/bpf/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexei Starovoitov May 16, 2019, 6:35 p.m. UTC | #1
On Tue, May 14, 2019 at 7:43 PM Chenbo Feng <fengc@google.com> wrote:
>
> For iptable module to load a bpf program from a pinned location, it
> only retrieve a loaded program and cannot change the program content so
> requiring a write permission for it might not be necessary.
> Also when adding or removing an unrelated iptable rule, it might need to
> flush and reload the xt_bpf related rules as well and triggers the inode
> permission check. It might be better to remove the write premission
> check for the inode so we won't need to grant write access to all the
> processes that flush and restore iptables rules.
>
> Signed-off-by: Chenbo Feng <fengc@google.com>

Applied. The fix makes sense to me.
Chenbo Feng May 17, 2019, 12:53 a.m. UTC | #2
On 5/16/19 11:35 AM, Alexei Starovoitov wrote:
> On Tue, May 14, 2019 at 7:43 PM Chenbo Feng <fengc@google.com> wrote:
>> For iptable module to load a bpf program from a pinned location, it
>> only retrieve a loaded program and cannot change the program content so
>> requiring a write permission for it might not be necessary.
>> Also when adding or removing an unrelated iptable rule, it might need to
>> flush and reload the xt_bpf related rules as well and triggers the inode
>> permission check. It might be better to remove the write premission
>> check for the inode so we won't need to grant write access to all the
>> processes that flush and restore iptables rules.
>>
>> Signed-off-by: Chenbo Feng <fengc@google.com>
> Applied. The fix makes sense to me.

Thanks for accepting it Alexei, could you also queue it up for the 
stable as well?


Chenbo Feng
diff mbox series

Patch

diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
index bc53e5b20ddc..84a80b02db99 100644
--- a/kernel/bpf/inode.c
+++ b/kernel/bpf/inode.c
@@ -518,7 +518,7 @@  int bpf_obj_get_user(const char __user *pathname, int flags)
 static struct bpf_prog *__get_prog_inode(struct inode *inode, enum bpf_prog_type type)
 {
 	struct bpf_prog *prog;
-	int ret = inode_permission(inode, MAY_READ | MAY_WRITE);
+	int ret = inode_permission(inode, MAY_READ);
 	if (ret)
 		return ERR_PTR(ret);