diff mbox series

[net] net/bpfilter: initialize pos in __bpfilter_process_sockopt

Message ID 20200730160900.187157-1-hch@lst.de
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [net] net/bpfilter: initialize pos in __bpfilter_process_sockopt | expand

Commit Message

Christoph Hellwig July 30, 2020, 4:09 p.m. UTC
__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")
Reported-by: Christian Brauner <christian.brauner@ubuntu.com>
Reported-by: Rodrigo Madera <rodrigo.madera@gmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rodrigo Madera <rodrigo.madera@gmail.com>
---
 net/bpfilter/bpfilter_kern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christian Brauner July 30, 2020, 4:13 p.m. UTC | #1
On Thu, Jul 30, 2020 at 06:09:00PM +0200, Christoph Hellwig wrote:
> __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/

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

s/patter/pattern/

> rw_verify_area happy.
> 
> Fixes: 6955a76fbcd5 ("bpfilter: switch to kernel_write")
> Reported-by: Christian Brauner <christian.brauner@ubuntu.com>
> Reported-by: Rodrigo Madera <rodrigo.madera@gmail.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: Rodrigo Madera <rodrigo.madera@gmail.com>
> ---

Thanks for tracking this down, Christoph! This fixes the logging issue
for me.
Tested-by: Christian Brauner <christian.brauner@ubuntu.com>
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>

>  net/bpfilter/bpfilter_kern.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/bpfilter/bpfilter_kern.c b/net/bpfilter/bpfilter_kern.c
> index 1905e01c3aa9a7..4494ea6056cdb8 100644
> --- a/net/bpfilter/bpfilter_kern.c
> +++ b/net/bpfilter/bpfilter_kern.c
> @@ -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;
>  
> -- 
> 2.27.0
>
Daniel Borkmann July 31, 2020, 12:07 a.m. UTC | #2
On 7/30/20 6:13 PM, Christian Brauner wrote:
> On Thu, Jul 30, 2020 at 06:09:00PM +0200, Christoph Hellwig wrote:
>> __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/
> 
>> position, which can lead to a failure depending on the exact stack
>> initialization patter.  Initialize the variable to zero to make
> 
> s/patter/pattern/
> 
>> rw_verify_area happy.
>>
>> Fixes: 6955a76fbcd5 ("bpfilter: switch to kernel_write")
>> Reported-by: Christian Brauner <christian.brauner@ubuntu.com>
>> Reported-by: Rodrigo Madera <rodrigo.madera@gmail.com>
>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> Tested-by: Rodrigo Madera <rodrigo.madera@gmail.com>
>> ---
> 
> Thanks for tracking this down, Christoph! This fixes the logging issue
> for me.
> Tested-by: Christian Brauner <christian.brauner@ubuntu.com>
> Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>

Applied to bpf & fixed up the typos in the commit msg, thanks everyone!
Alexei Starovoitov Aug. 1, 2020, 7:48 p.m. UTC | #3
On Fri, Jul 31, 2020 at 02:07:42AM +0200, Daniel Borkmann wrote:
> On 7/30/20 6:13 PM, Christian Brauner wrote:
> > On Thu, Jul 30, 2020 at 06:09:00PM +0200, Christoph Hellwig wrote:
> > > __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/
> > 
> > > position, which can lead to a failure depending on the exact stack
> > > initialization patter.  Initialize the variable to zero to make
> > 
> > s/patter/pattern/
> > 
> > > rw_verify_area happy.
> > > 
> > > Fixes: 6955a76fbcd5 ("bpfilter: switch to kernel_write")
> > > Reported-by: Christian Brauner <christian.brauner@ubuntu.com>
> > > Reported-by: Rodrigo Madera <rodrigo.madera@gmail.com>
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > > Tested-by: Rodrigo Madera <rodrigo.madera@gmail.com>
> > > ---
> > 
> > Thanks for tracking this down, Christoph! This fixes the logging issue
> > for me.
> > Tested-by: Christian Brauner <christian.brauner@ubuntu.com>
> > Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
> 
> 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...
Daniel Borkmann Aug. 3, 2020, 2:56 p.m. UTC | #4
On 8/1/20 9:48 PM, Alexei Starovoitov wrote:
> On Fri, Jul 31, 2020 at 02:07:42AM +0200, Daniel Borkmann wrote:
>> On 7/30/20 6:13 PM, Christian Brauner wrote:
>>> On Thu, Jul 30, 2020 at 06:09:00PM +0200, Christoph Hellwig wrote:
>>>> __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/
>>>
>>>> position, which can lead to a failure depending on the exact stack
>>>> initialization patter.  Initialize the variable to zero to make
>>>
>>> s/patter/pattern/
>>>
>>>> rw_verify_area happy.
>>>>
>>>> Fixes: 6955a76fbcd5 ("bpfilter: switch to kernel_write")
>>>> Reported-by: Christian Brauner <christian.brauner@ubuntu.com>
>>>> Reported-by: Rodrigo Madera <rodrigo.madera@gmail.com>
>>>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>>>> Tested-by: Rodrigo Madera <rodrigo.madera@gmail.com>
>>>> ---
>>>
>>> Thanks for tracking this down, Christoph! This fixes the logging issue
>>> for me.
>>> Tested-by: Christian Brauner <christian.brauner@ubuntu.com>
>>> Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
>>
>> 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/
Rodrigo Madera Aug. 3, 2020, 3:36 p.m. UTC | #5
On Mon, Aug 03, 2020 at 04:56:35PM +0200, Daniel Borkmann wrote:
> 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
diff mbox series

Patch

diff --git a/net/bpfilter/bpfilter_kern.c b/net/bpfilter/bpfilter_kern.c
index 1905e01c3aa9a7..4494ea6056cdb8 100644
--- a/net/bpfilter/bpfilter_kern.c
+++ b/net/bpfilter/bpfilter_kern.c
@@ -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;