Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1166f5c1 authored by Harold Huang's avatar Harold Huang Committed by Greg Kroah-Hartman
Browse files

tuntap: add sanity checks about msg_controllen in sendmsg

[ Upstream commit 74a335a07a17d131b9263bfdbdcb5e40673ca9ca ]

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.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fe8dd45bb7556246c6b76277b1ba4296c91c2505



Reported-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Suggested-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarHarold Huang <baymaxhuang@gmail.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20220303022441.383865-1-baymaxhuang@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent c68dd44f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1214,7 +1214,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);
+2 −1
Original line number Diff line number Diff line
@@ -2561,7 +2561,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;
+1 −0
Original line number Diff line number Diff line
@@ -472,6 +472,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");