Skip to contentSkip to conversation

net/bpfilter: initialize pos in __bpfilter_process_sockopt

PATCH Applied Christoph Hellwig 5 participants 6 messages Jul 30, 2020 – Aug 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/bpfilter: initialize pos in __bpfilter_process_sockopt

__bpfilter_process_sockopt never initialized the pos variable passed to the pipe write. This has been mostly harmless in the past as pipes ignore the offset, but the switch to kernel_write no verified the position, which can lead to a failure depending on the exact stack initialization patter. Initialize the variable to zero to make rw_verify_area happy.

Fixes 6955a76fbcd5 ("bpfilter: switch to kernel_write")
---
 net/bpfilter/bpfilter_kern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bpfilter/bpfilter_kern.c +1 -1
index 1905e01c3aa9a7..4494ea6056cdb8 100644
@@ -39,7 +39,7 @@ static int __bpfilter_process_sockopt(struct sock *sk, int optname,
 {
 	struct mbox_request req;
 	struct mbox_reply reply;
-	loff_t pos;
+	loff_t pos = 0;
 	ssize_t n;
 	int ret = -EFAULT;
 
Signature · 1 line
2.27.0
Tested-by Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Christoph Hellwig

__bpfilter_process_sockopt never initialized the pos variable passed to the pipe write. This has been mostly harmless in the past as pipes ignore the offset, but the switch to kernel_write no verified the

s/no/now/

Quoted 2 lines

position, which can lead to a failure depending on the exact stack initialization patter. Initialize the variable to zero to make

s/patter/pattern/

Quoted 8 lines

rw_verify_area happy.

Fixes 6955a76fbcd5 ("bpfilter: switch to kernel_write")

---

Thanks for tracking this down, Christoph! This fixes the logging issue for me.

Quoted 19 lines
 net/bpfilter/bpfilter_kern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bpfilter/bpfilter_kern.c +1 -1
index 1905e01c3aa9a7..4494ea6056cdb8 100644
@@ -39,7 +39,7 @@ static int __bpfilter_process_sockopt(struct sock *sk, int optname,
 {
 	struct mbox_request req;
 	struct mbox_reply reply;
-	loff_t pos;
+	loff_t pos = 0;
 	ssize_t n;
 	int ret = -EFAULT;
 
Signature · 1 line
2.27.0
maintainer Applied
#2 lore raw
Quoted 21 lines · Christian Brauner
Quoted 3 lines · Christoph Hellwig

__bpfilter_process_sockopt never initialized the pos variable passed to the pipe write. This has been mostly harmless in the past as pipes ignore the offset, but the switch to kernel_write no verified the

s/no/now/

Quoted 2 lines

position, which can lead to a failure depending on the exact stack initialization patter. Initialize the variable to zero to make

s/patter/pattern/

Quoted 8 lines

rw_verify_area happy.

Fixes 6955a76fbcd5 ("bpfilter: switch to kernel_write")

---

Quoted 4 lines

Thanks for tracking this down, Christoph! This fixes the logging issue for me.

Applied to bpf & fixed up the typos in the commit msg, thanks everyone!

#3 lore raw
Quoted 22 lines · Daniel Borkmann
Quoted 21 lines · Christian Brauner
Quoted 3 lines · Christoph Hellwig

__bpfilter_process_sockopt never initialized the pos variable passed to the pipe write. This has been mostly harmless in the past as pipes ignore the offset, but the switch to kernel_write no verified the

s/no/now/

Quoted 2 lines

position, which can lead to a failure depending on the exact stack initialization patter. Initialize the variable to zero to make

s/patter/pattern/

Quoted 8 lines

rw_verify_area happy.

Fixes 6955a76fbcd5 ("bpfilter: switch to kernel_write")

---

Quoted 6 lines
Quoted 4 lines

Thanks for tracking this down, Christoph! This fixes the logging issue for me.

Applied to bpf & fixed up the typos in the commit msg, thanks everyone!

Daniel,
why is it necessary in bpf tree?

I fixed it already in bpf-next in commit a4fa458950b4 ("bpfilter: Initialize pos variable") two weeks ago...

maintainer
#4 lore raw
Quoted 28 lines · Alexei Starovoitov
Quoted 27 lines · Daniel Borkmann
Quoted 25 lines · Christian Brauner
Quoted 3 lines · Christoph Hellwig

__bpfilter_process_sockopt never initialized the pos variable passed to the pipe write. This has been mostly harmless in the past as pipes ignore the offset, but the switch to kernel_write no verified the

s/no/now/

Quoted 2 lines

position, which can lead to a failure depending on the exact stack initialization patter. Initialize the variable to zero to make

s/patter/pattern/

Quoted 8 lines

rw_verify_area happy.

Fixes 6955a76fbcd5 ("bpfilter: switch to kernel_write")

---

Thanks for tracking this down, Christoph! This fixes the logging issue for me.

Quoted 7 lines
Quoted 1 line

Applied to bpf & fixed up the typos in the commit msg, thanks everyone!

Daniel,
why is it necessary in bpf tree?

I fixed it already in bpf-next in commit a4fa458950b4 ("bpfilter: Initialize pos variable") two weeks ago...

Several folks reported that with v5.8-rc kernels their console is spammed with 'bpfilter: write fail' messages [0]. Given this affected the 5.8 release and the fix was a one-line change, it felt appropriate to route it there. Why was a4fa458950b4 not pushed into bpf tree given it was affected there too? Either way, we can undo the double pos assignment upon tree sync..

[0] https://lore.kernel.org/lkml/20200727104636.nuz3u4xb7ba7ue5a@wittgenstein/

#5 lore raw
Quoted 7 lines · Daniel Borkmann

On 8/1/20 9:48 PM, Alexei Starovoitov wrote:

Several folks reported that with v5.8-rc kernels their console is spammed with 'bpfilter: write fail' messages [0]. Given this affected the 5.8 release and the fix was a one-line change, it felt appropriate to route it there. Why was a4fa458950b4 not pushed into bpf tree given it was affected there too? Either way, we can undo the double pos assignment upon tree sync..

Just as a side note, please note it was more than spamming on the console.

It prevented the subsystem from working at all.

Best regards,
Madera