* [PATCH] net: compat: fix msg_controllen overflow in scm_detach_fds_compat()
@ 2019-06-04 12:31 Young Xiao
2019-06-04 12:46 ` Daniel Borkmann
0 siblings, 1 reply; 3+ messages in thread
From: Young Xiao @ 2019-06-04 12:31 UTC (permalink / raw)
To: davem, netdev, linux-kernel; +Cc: Young Xiao
There is a missing check between kmsg->msg_controllen and cmlen,
which can possibly lead to overflow.
This bug is similar to vulnerability that was fixed in commit 6900317f5eff
("net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds").
Signed-off-by: Young Xiao <92siuyang@gmail.com>
---
net/compat.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/compat.c b/net/compat.c
index a031bd3..8e74dfb 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -301,6 +301,8 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
err = put_user(cmlen, &cm->cmsg_len);
if (!err) {
cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
+ if (kmsg->msg_controllen < cmlen)
+ cmlen = kmsg->msg_controllen;
kmsg->msg_control += cmlen;
kmsg->msg_controllen -= cmlen;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: compat: fix msg_controllen overflow in scm_detach_fds_compat()
2019-06-04 12:31 [PATCH] net: compat: fix msg_controllen overflow in scm_detach_fds_compat() Young Xiao
@ 2019-06-04 12:46 ` Daniel Borkmann
2019-06-04 12:54 ` Yang Xiao
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2019-06-04 12:46 UTC (permalink / raw)
To: Young Xiao; +Cc: davem, netdev, linux-kernel, eric.dumazet
On 06/04/2019 02:31 PM, Young Xiao wrote:
> There is a missing check between kmsg->msg_controllen and cmlen,
> which can possibly lead to overflow.
>
> This bug is similar to vulnerability that was fixed in commit 6900317f5eff
> ("net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds").
Back then I mentioned in commit 6900317f5eff:
In case of MSG_CMSG_COMPAT (scm_detach_fds_compat()), I haven't seen an
issue in my tests as alignment seems always on 4 byte boundary. Same
should be in case of native 32 bit, where we end up with 4 byte boundaries
as well.
Do you have an actual reproducer or is it based on code inspection?
> Signed-off-by: Young Xiao <92siuyang@gmail.com>
> ---
> net/compat.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/compat.c b/net/compat.c
> index a031bd3..8e74dfb 100644
> --- a/net/compat.c
> +++ b/net/compat.c
> @@ -301,6 +301,8 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
> err = put_user(cmlen, &cm->cmsg_len);
> if (!err) {
> cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
> + if (kmsg->msg_controllen < cmlen)
> + cmlen = kmsg->msg_controllen;
> kmsg->msg_control += cmlen;
> kmsg->msg_controllen -= cmlen;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: compat: fix msg_controllen overflow in scm_detach_fds_compat()
2019-06-04 12:46 ` Daniel Borkmann
@ 2019-06-04 12:54 ` Yang Xiao
0 siblings, 0 replies; 3+ messages in thread
From: Yang Xiao @ 2019-06-04 12:54 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: David Miller, netdev, LKML, Eric Dumazet
On Tue, Jun 4, 2019 at 8:46 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 06/04/2019 02:31 PM, Young Xiao wrote:
> > There is a missing check between kmsg->msg_controllen and cmlen,
> > which can possibly lead to overflow.
> >
> > This bug is similar to vulnerability that was fixed in commit 6900317f5eff
> > ("net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds").
>
> Back then I mentioned in commit 6900317f5eff:
>
> In case of MSG_CMSG_COMPAT (scm_detach_fds_compat()), I haven't seen an
> issue in my tests as alignment seems always on 4 byte boundary. Same
> should be in case of native 32 bit, where we end up with 4 byte boundaries
> as well.
>
> Do you have an actual reproducer or is it based on code inspection?
based on inspection.
>
> > Signed-off-by: Young Xiao <92siuyang@gmail.com>
> > ---
> > net/compat.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/net/compat.c b/net/compat.c
> > index a031bd3..8e74dfb 100644
> > --- a/net/compat.c
> > +++ b/net/compat.c
> > @@ -301,6 +301,8 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
> > err = put_user(cmlen, &cm->cmsg_len);
> > if (!err) {
> > cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
> > + if (kmsg->msg_controllen < cmlen)
> > + cmlen = kmsg->msg_controllen;
> > kmsg->msg_control += cmlen;
> > kmsg->msg_controllen -= cmlen;
> > }
> >
>
--
Best regards!
Young
-----------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-04 12:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04 12:31 [PATCH] net: compat: fix msg_controllen overflow in scm_detach_fds_compat() Young Xiao
2019-06-04 12:46 ` Daniel Borkmann
2019-06-04 12:54 ` Yang Xiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).