From: Cong Wang <hidden> Date: 2020-08-11 03:57:33
On Mon, Aug 10, 2020 at 3:10 PM Peilin Ye [off-list ref] wrote:
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Which exact 'cmd' is it here?
I _guess_ it is one of those uninitialized in set_arglen[], which is 0.
But if that is the case, should it be initialized to
sizeof(struct ip_vs_service_user) instead because ip_vs_copy_usvc_compat()
is called anyway. Or, maybe we should just ban len==0 case.
In either case, it does not look like you fix it correctly.
Thanks.
From: Peilin Ye <hidden> Date: 2020-08-11 05:09:35
On Mon, Aug 10, 2020 at 08:57:19PM -0700, Cong Wang wrote:
On Mon, Aug 10, 2020 at 3:10 PM Peilin Ye [off-list ref] wrote:
quoted
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Which exact 'cmd' is it here?
I _guess_ it is one of those uninitialized in set_arglen[], which is 0.
Yes, it was `IP_VS_SO_SET_NONE`, implicitly initialized to zero.
But if that is the case, should it be initialized to
sizeof(struct ip_vs_service_user) instead because ip_vs_copy_usvc_compat()
is called anyway. Or, maybe we should just ban len==0 case.
I see. I think the latter would be easier, but we cannot ban all of
them, since the function does something with `IP_VS_SO_SET_FLUSH`, which
is a `len == 0` case.
Maybe we do something like this?
@@ -2432,6 +2432,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_SET_MAX) return -EINVAL;+ if (len == 0 && cmd != IP_VS_SO_SET_FLUSH)+ return -EINVAL; if (len != set_arglen[CMDID(cmd)]) { IP_VS_DBG(1, "set_ctl: len %u != %u\n", len, set_arglen[CMDID(cmd)]);
@@ -2547,9 +2549,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) break; case IP_VS_SO_SET_DELDEST: ret = ip_vs_del_dest(svc, &udest);- break;- default:- ret = -EINVAL; } out_unlock:
Thank you,
Peilin Ye
In either case, it does not look like you fix it correctly.
Thanks.
On Mon, Aug 10, 2020 at 08:57:19PM -0700, Cong Wang wrote:
quoted
On Mon, Aug 10, 2020 at 3:10 PM Peilin Ye [off-list ref] wrote:
quoted
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Which exact 'cmd' is it here?
I _guess_ it is one of those uninitialized in set_arglen[], which is 0.
Yes, it was `IP_VS_SO_SET_NONE`, implicitly initialized to zero.
quoted
But if that is the case, should it be initialized to
sizeof(struct ip_vs_service_user) instead because ip_vs_copy_usvc_compat()
is called anyway. Or, maybe we should just ban len==0 case.
I see. I think the latter would be easier, but we cannot ban all of
them, since the function does something with `IP_VS_SO_SET_FLUSH`, which
is a `len == 0` case.
Maybe we do something like this?
Yes, only IP_VS_SO_SET_FLUSH uses len 0. We can go with
this change but you do not need to target net tree, as the
problem is not fatal net-next works too. What happens is
that we may lookup services with random search keys which
is harmless.
Another option is to add new block after this one:
} else if (cmd == IP_VS_SO_SET_TIMEOUT) {
/* Set timeout values for (tcp tcpfin udp) */
ret = ip_vs_set_timeout(ipvs, (struct ip_vs_timeout_user *)arg);
goto out_unlock;
}
such as:
} else if (!len) {
/* No more commands with len=0 below */
ret = -EINVAL;
goto out_unlock;
}
It give more chance for future commands to use len=0
but the drawback is that the check happens under mutex. So, I'm
fine with both versions, it is up to you to decide :)
quoted hunk
@@ -2432,6 +2432,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_SET_MAX) return -EINVAL;+ if (len == 0 && cmd != IP_VS_SO_SET_FLUSH)+ return -EINVAL; if (len != set_arglen[CMDID(cmd)]) { IP_VS_DBG(1, "set_ctl: len %u != %u\n", len, set_arglen[CMDID(cmd)]);
@@ -2547,9 +2549,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) break; case IP_VS_SO_SET_DELDEST: ret = ip_vs_del_dest(svc, &udest);- break;- default:- ret = -EINVAL; } out_unlock:
From: Peilin Ye <hidden> Date: 2020-08-11 07:19:20
On Tue, Aug 11, 2020 at 09:58:46AM +0300, Julian Anastasov wrote:
Hello,
On Tue, 11 Aug 2020, Peilin Ye wrote:
quoted
On Mon, Aug 10, 2020 at 08:57:19PM -0700, Cong Wang wrote:
quoted
On Mon, Aug 10, 2020 at 3:10 PM Peilin Ye [off-list ref] wrote:
quoted
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Which exact 'cmd' is it here?
I _guess_ it is one of those uninitialized in set_arglen[], which is 0.
Yes, it was `IP_VS_SO_SET_NONE`, implicitly initialized to zero.
quoted
But if that is the case, should it be initialized to
sizeof(struct ip_vs_service_user) instead because ip_vs_copy_usvc_compat()
is called anyway. Or, maybe we should just ban len==0 case.
I see. I think the latter would be easier, but we cannot ban all of
them, since the function does something with `IP_VS_SO_SET_FLUSH`, which
is a `len == 0` case.
Maybe we do something like this?
Yes, only IP_VS_SO_SET_FLUSH uses len 0. We can go with
this change but you do not need to target net tree, as the
problem is not fatal net-next works too. What happens is
that we may lookup services with random search keys which
is harmless.
I see, I'll target net-next instead.
Another option is to add new block after this one:
} else if (cmd == IP_VS_SO_SET_TIMEOUT) {
/* Set timeout values for (tcp tcpfin udp) */
ret = ip_vs_set_timeout(ipvs, (struct ip_vs_timeout_user *)arg);
goto out_unlock;
}
such as:
} else if (!len) {
/* No more commands with len=0 below */
ret = -EINVAL;
goto out_unlock;
}
It give more chance for future commands to use len=0
but the drawback is that the check happens under mutex. So, I'm
fine with both versions, it is up to you to decide :)
Ah, this seems much cleaner. I'll send v2 soon, thank you!
Peilin Ye
quoted
@@ -2432,6 +2432,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_SET_MAX) return -EINVAL;+ if (len == 0 && cmd != IP_VS_SO_SET_FLUSH)+ return -EINVAL; if (len != set_arglen[CMDID(cmd)]) { IP_VS_DBG(1, "set_ctl: len %u != %u\n", len, set_arglen[CMDID(cmd)]);
@@ -2547,9 +2549,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) break; case IP_VS_SO_SET_DELDEST: ret = ip_vs_del_dest(svc, &udest);- break;- default:- ret = -EINVAL; } out_unlock:
@@ -2471,6 +2471,10 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)/* Set timeout values for (tcp tcpfin udp) */ret=ip_vs_set_timeout(ipvs,(structip_vs_timeout_user*)arg);gotoout_unlock;+}elseif(!len){+/* No more commands with len == 0 below */+ret=-EINVAL;+gotoout_unlock;}usvc_compat=(structip_vs_service_user*)arg;
@@ -2547,9 +2551,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)break;caseIP_VS_SO_SET_DELDEST:ret=ip_vs_del_dest(svc,&udest);-break;-default:-ret=-EINVAL;}out_unlock:
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Reported-by: syzbot+23b5f9e7caf61d9a3898@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=46ebfb92a8a812621a001ef04d90dfa459520fe2
Suggested-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Peilin Ye <redacted>
Looks good to me, thanks!
Acked-by: Julian Anastasov <ja@ssi.bg>
quoted hunk
---
Changes in v2:
- Target net-next tree. (Suggested by Julian Anastasov [off-list ref])
- Reject all `len == 0` requests except `IP_VS_SO_SET_FLUSH`, instead
of initializing `arg`. (Suggested by Cong Wang
[off-list ref], Julian Anastasov [off-list ref])
net/netfilter/ipvs/ip_vs_ctl.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
@@ -2471,6 +2471,10 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)/* Set timeout values for (tcp tcpfin udp) */ret=ip_vs_set_timeout(ipvs,(structip_vs_timeout_user*)arg);gotoout_unlock;+}elseif(!len){+/* No more commands with len == 0 below */+ret=-EINVAL;+gotoout_unlock;}usvc_compat=(structip_vs_service_user*)arg;
@@ -2547,9 +2551,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)break;caseIP_VS_SO_SET_DELDEST:ret=ip_vs_del_dest(svc,&udest);-break;-default:-ret=-EINVAL;}out_unlock:
From: Simon Horman <horms@verge.net.au> Date: 2020-08-11 13:00:07
On Tue, Aug 11, 2020 at 01:29:04PM +0300, Julian Anastasov wrote:
Hello,
On Tue, 11 Aug 2020, Peilin Ye wrote:
quoted
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Reported-by: syzbot+23b5f9e7caf61d9a3898@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=46ebfb92a8a812621a001ef04d90dfa459520fe2
Suggested-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Peilin Ye <redacted>
Looks good to me, thanks!
Acked-by: Julian Anastasov <ja@ssi.bg>
Pablo, could you consider this for nf-next or should we repost when
net-next re-opens?
Reviewed-by: Simon Horman <horms@verge.net.au>
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2020-08-13 01:28:46
On Tue, Aug 11, 2020 at 02:59:59PM +0200, Simon Horman wrote:
On Tue, Aug 11, 2020 at 01:29:04PM +0300, Julian Anastasov wrote:
quoted
Hello,
On Tue, 11 Aug 2020, Peilin Ye wrote:
quoted
do_ip_vs_set_ctl() is referencing uninitialized stack value when `len` is
zero. Fix it.
Reported-by: syzbot+23b5f9e7caf61d9a3898@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=46ebfb92a8a812621a001ef04d90dfa459520fe2
Suggested-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Peilin Ye <redacted>
Looks good to me, thanks!
Acked-by: Julian Anastasov <ja@ssi.bg>
Pablo, could you consider this for nf-next or should we repost when
net-next re-opens?
No worries, it will sit in netfilter's patchwork until net-next
reopens.