tuntap: add sanity checks about msg_controllen in sendmsg
Subsystems (7)
PATCH 1/1 tuntap: add sanity checks about msg_controllen in sendmsg
In patch [1], tun_msg_ctl was added to allow pass batched xdp buffers to tun_sendmsg. Although we donot use msg_controllen in this path, we should check msg_controllen to make sure the caller pass a valid msg_ctl.
--- drivers/net/tap.c | 3 ++- drivers/net/tun.c | 3 ++- drivers/vhost/net.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/tap.c +2 -1
@@ -1198,7 +1198,8 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,struct xdp_buff *xdp;int i; -if (ctl && (ctl->type ==TUN_MSG_PTR )) { +if (m->msg_controllen ==sizeof (struct tun_msg_ctl ) && + ctl && ctl->type ==TUN_MSG_PTR ) {for (i =0 ; i < ctl->num; i++) { xdp = &((struct xdp_buff *)ctl->ptr)[i];tap_get_user_xdp (q, xdp);
drivers/net/tun.c +2 -1
@@ -2501,7 +2501,8 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)if (!tun)return -EBADFD ; -if (ctl && (ctl->type ==TUN_MSG_PTR )) { +if (m->msg_controllen ==sizeof (struct tun_msg_ctl ) && + ctl && ctl->type ==TUN_MSG_PTR ) {struct tun_page tpage;int n = ctl->num;int flush =0 , queued =0 ;
drivers/vhost/net.c +1 -0
@@ -473,6 +473,7 @@ static void vhost_tx_batch(struct vhost_net *net, goto signal_used; msghdr->msg_control = &ctl; + msghdr->msg_controllen =sizeof (ctl); err = sock->ops->sendmsg (sock, msghdr,0 );if (unlikely (err <0 )) {vq_err (&nvq->vq,"Fail to batch sending packets\n" );
Signature · 1 line
2.27.0
Jakub Kicinski
maintainerQuoted 9 lines · On Tue, 1 Mar 2022 14:43:14 +0800 Harold Huang wrote:
In patch [1],
tun_msg_ctlwas added to allow pass batched xdp buffers totun_sendmsg. Although we donot usemsg_controllenin this path, we should checkmsg_controllento make sure the caller pass a validmsg_ctl.Reported-by Eric Dumazet <[email protected]>Suggested-by Jason Wang <[email protected]>Signed-off-by Harold Huang <[email protected]>
Would you mind resending the same patch? It looks like it depended on your other change so the build bot was unable to apply and test it.
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 1 Mar 2022 14:43:14 +0800 Harold Huang wrote:
In patch [1],
tun_msg_ctlwas added to allow pass batched xdp buffers totun_sendmsg. Although we donot usemsg_controllenin this path, we should checkmsg_controllento make sure the caller pass a validmsg_ctl.
Quoted 8 lines
Quoted 5 lines
Reported-by Eric Dumazet <[email protected]>Suggested-by Jason Wang <[email protected]>Signed-off-by Harold Huang <[email protected]>Would you mind resending the same patch? It looks like it depended on your other change so the build bot was unable to apply and test it.
Yes, it depends on this patch [1] which has been applied to netdev. I see this patch could be applied to netdev by git am. But if I use another patch that could be applied to linux master, it could not be applied to netdev anymore.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=fb3f903769e8
PATCH 1/1 tuntap: add sanity checks about msg_controllen in sendmsg
In reply to Harold HuangIn patch [1], tun_msg_ctl was added to allow pass batched xdp buffers to tun_sendmsg. Although we donot use msg_controllen in this path, we should check msg_controllen to make sure the caller pass a valid msg_ctl.
--- drivers/net/tap.c | 3 ++- drivers/net/tun.c | 3 ++- drivers/vhost/net.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/tap.c +2 -1
@@ -1198,7 +1198,8 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,struct xdp_buff *xdp;int i; -if (ctl && (ctl->type ==TUN_MSG_PTR )) { +if (m->msg_controllen ==sizeof (struct tun_msg_ctl ) && + ctl && ctl->type ==TUN_MSG_PTR ) {for (i =0 ; i < ctl->num; i++) { xdp = &((struct xdp_buff *)ctl->ptr)[i];tap_get_user_xdp (q, xdp);
drivers/net/tun.c +2 -1
@@ -2501,7 +2501,8 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)if (!tun)return -EBADFD ; -if (ctl && (ctl->type ==TUN_MSG_PTR )) { +if (m->msg_controllen ==sizeof (struct tun_msg_ctl ) && + ctl && ctl->type ==TUN_MSG_PTR ) {struct tun_page tpage;int n = ctl->num;int flush =0 , queued =0 ;
drivers/vhost/net.c +1 -0
@@ -473,6 +473,7 @@ static void vhost_tx_batch(struct vhost_net *net, goto signal_used; msghdr->msg_control = &ctl; + msghdr->msg_controllen =sizeof (ctl); err = sock->ops->sendmsg (sock, msghdr,0 );if (unlikely (err <0 )) {vq_err (&nvq->vq,"Fail to batch sending packets\n" );
Signature · 1 line
2.27.0
Quoted 9 lines · Harold Huang
In patch [1],
tun_msg_ctlwas added to allow pass batched xdp buffers totun_sendmsg. Although we donot usemsg_controllenin this path, we should checkmsg_controllento make sure the caller pass a validmsg_ctl.Reported-by Eric Dumazet <[email protected]>Suggested-by Jason Wang <[email protected]>Signed-off-by Harold Huang <[email protected]>
Quoted 46 lines
--- drivers/net/tap.c | 3 ++- drivers/net/tun.c | 3 ++- drivers/vhost/net.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)drivers/net/tap.c +2
-1@@ -1198,7 +1198,8 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,struct xdp_buff *xdp;int i; -if (ctl && (ctl->type ==TUN_MSG_PTR )) { +if (m->msg_controllen ==sizeof (struct tun_msg_ctl ) && + ctl && ctl->type ==TUN_MSG_PTR ) {for (i =0 ; i < ctl->num; i++) { xdp = &((struct xdp_buff *)ctl->ptr)[i];tap_get_user_xdp (q, xdp);drivers/net/tun.c +2
-1@@ -2501,7 +2501,8 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)if (!tun)return -EBADFD ; -if (ctl && (ctl->type ==TUN_MSG_PTR )) { +if (m->msg_controllen ==sizeof (struct tun_msg_ctl ) && + ctl && ctl->type ==TUN_MSG_PTR ) {struct tun_page tpage;int n = ctl->num;int flush =0 , queued =0 ;drivers/vhost/net.c +1
-0@@ -473,6 +473,7 @@ static void vhost_tx_batch(struct vhost_net *net, goto signal_used; msghdr->msg_control = &ctl; + msghdr->msg_controllen =sizeof (ctl); err = sock->ops->sendmsg (sock, msghdr,0 );if (unlikely (err <0 )) {vq_err (&nvq->vq,"Fail to batch sending packets\n" );
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Thu, 3 Mar 2022 10:24:40 +0800 you wrote:
In patch [1],
tun_msg_ctlwas added to allow pass batched xdp buffers totun_sendmsg. Although we donot usemsg_controllenin this path, we should checkmsg_controllento make sure the caller pass a validmsg_ctl.Reported-by Eric Dumazet <[email protected]>Suggested-by Jason Wang <[email protected]>Signed-off-by Harold Huang <[email protected]>[...]
Here is the summary with links:
- [net-next] tuntap: add sanity checks about msg_controllen in sendmsg
https://git.kernel.org/netdev/net-next/c/74a335a07a17
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html