* Re: [RFC 1/1] whitelisting UDP GSO and GRO cmsgs
2020-11-23 15:35 [RFC 1/1] whitelisting UDP GSO and GRO cmsgs Victor Stewart
@ 2020-11-23 15:40 ` Victor Stewart
2020-11-23 20:33 ` Pavel Begunkov
1 sibling, 0 replies; 4+ messages in thread
From: Victor Stewart @ 2020-11-23 15:40 UTC (permalink / raw)
To: io-uring, Jens Axboe
sorry there was a typo "msr" instead of "msg"
diff --git a/net/socket.c b/net/socket.c
index 6e6cccc2104f..31ebd0440e30 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2416,9 +2416,9 @@ static int ___sys_sendmsg(struct socket *sock,
struct user_msghdr __user *msg,
long __sys_sendmsg_sock(struct socket *sock, struct msghdr *msg,
unsigned int flags)
{
- /* disallow ancillary data requests from this path */
if (msg->msg_control || msg->msg_controllen)
- return -EINVAL;
+ if (!__sys_whitelisted_cmsghdrs(msg))
+ return -EINVAL;
return ____sys_sendmsg(sock, msg, flags, NULL, 0);
}
@@ -2620,6 +2620,15 @@ static int ___sys_recvmsg(struct socket *sock,
struct user_msghdr __user *msg,
return err;
}
+static bool __sys_whitelisted_cmsghdrs(struct msghdr *msg)
+{
+ for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL;
cmsg = CMSG_NXTHDR(message, cmsg))
+ if (cmsg->cmsg_level != SOL_UDP || (cmsg->cmsg_type !=
UDP_GRO && cmsg->cmsg_type != UDP_SEGMENT))
+ return false;
+
+ return true;
+}
+
/*
* BSD recvmsg interface
*/
@@ -2630,7 +2639,7 @@ long __sys_recvmsg_sock(struct socket *sock,
struct msghdr *msg,
{
if (msg->msg_control || msg->msg_controllen) {
/* disallow ancillary data reqs unless cmsg is plain data */
- if (!(sock->ops->flags & PROTO_CMSG_DATA_ONLY))
+ if (!( sock->ops->flags & PROTO_CMSG_DATA_ONLY ||
__sys_whitelisted_cmsghdrs(msg) ))
return -EINVAL;
}
On Mon, Nov 23, 2020 at 3:35 PM Victor Stewart <[email protected]> wrote:
>
> add __sys_whitelisted_cmsghdrs() and configure __sys_recvmsg_sock and
> __sys_sendmsg_sock to use it.
>
> Signed-off by: Victor Stewart <[email protected]>
> ---
> net/socket.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/net/socket.c b/net/socket.c
> index 6e6cccc2104f..44e28bb08bbe 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -2416,9 +2416,9 @@ static int ___sys_sendmsg(struct socket *sock,
> struct user_msghdr __user *msg,
> long __sys_sendmsg_sock(struct socket *sock, struct msghdr *msg,
> unsigned int flags)
> {
> - /* disallow ancillary data requests from this path */
> if (msg->msg_control || msg->msg_controllen)
> - return -EINVAL;
> + if (!__sys_whitelisted_cmsghdrs(msr))
> + return -EINVAL;
>
> return ____sys_sendmsg(sock, msg, flags, NULL, 0);
> }
> @@ -2620,6 +2620,15 @@ static int ___sys_recvmsg(struct socket *sock,
> struct user_msghdr __user *msg,
> return err;
> }
>
> +static bool __sys_whitelisted_cmsghdrs(struct msghdr *msg)
> +{
> + for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL;
> cmsg = CMSG_NXTHDR(message, cmsg))
> + if (cmsg->cmsg_level != SOL_UDP || (cmsg->cmsg_type !=
> UDP_GRO && cmsg->cmsg_type != UDP_SEGMENT))
> + return false;
> +
> + return true;
> +}
> +
> /*
> * BSD recvmsg interface
> */
> @@ -2630,7 +2639,7 @@ long __sys_recvmsg_sock(struct socket *sock,
> struct msghdr *msg,
> {
> if (msg->msg_control || msg->msg_controllen) {
> /* disallow ancillary data reqs unless cmsg is plain data */
> - if (!(sock->ops->flags & PROTO_CMSG_DATA_ONLY))
> + if (!( sock->ops->flags & PROTO_CMSG_DATA_ONLY ||
> __sys_whitelisted_cmsghdrs(msr) ))
> return -EINVAL;
> }
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC 1/1] whitelisting UDP GSO and GRO cmsgs
2020-11-23 15:35 [RFC 1/1] whitelisting UDP GSO and GRO cmsgs Victor Stewart
2020-11-23 15:40 ` Victor Stewart
@ 2020-11-23 20:33 ` Pavel Begunkov
2020-11-23 21:23 ` Victor Stewart
1 sibling, 1 reply; 4+ messages in thread
From: Pavel Begunkov @ 2020-11-23 20:33 UTC (permalink / raw)
To: Victor Stewart, io-uring, Jens Axboe
On 23/11/2020 15:35, Victor Stewart wrote:
> add __sys_whitelisted_cmsghdrs() and configure __sys_recvmsg_sock and
> __sys_sendmsg_sock to use it.
They haven't been disabled without a reason, and that's not only
because of creds. Did you verify that it's safe to allow those?
>
> Signed-off by: Victor Stewart <[email protected]>
> ---
> net/socket.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/net/socket.c b/net/socket.c
> index 6e6cccc2104f..44e28bb08bbe 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -2416,9 +2416,9 @@ static int ___sys_sendmsg(struct socket *sock,
> struct user_msghdr __user *msg,
> long __sys_sendmsg_sock(struct socket *sock, struct msghdr *msg,
> unsigned int flags)
> {
> - /* disallow ancillary data requests from this path */
> if (msg->msg_control || msg->msg_controllen)
> - return -EINVAL;
> + if (!__sys_whitelisted_cmsghdrs(msr))
Its definition below and I don't see a forward declaration anywhere.
Did you even compile this?
> + return -EINVAL;
>
> return ____sys_sendmsg(sock, msg, flags, NULL, 0);
> }
> @@ -2620,6 +2620,15 @@ static int ___sys_recvmsg(struct socket *sock,
> struct user_msghdr __user *msg,
> return err;
> }
>
> +static bool __sys_whitelisted_cmsghdrs(struct msghdr *msg)
Don't call it __sys*
> +{
> + for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL;
> cmsg = CMSG_NXTHDR(message, cmsg))
no var declarations in for, run checkpatch.pl first
> + if (cmsg->cmsg_level != SOL_UDP || (cmsg->cmsg_type !=
> UDP_GRO && cmsg->cmsg_type != UDP_SEGMENT))
> + return false;
> +
> + return true;
> +}
> +
> /*
> * BSD recvmsg interface
> */
> @@ -2630,7 +2639,7 @@ long __sys_recvmsg_sock(struct socket *sock,
> struct msghdr *msg,
> {
> if (msg->msg_control || msg->msg_controllen) {
> /* disallow ancillary data reqs unless cmsg is plain data */
> - if (!(sock->ops->flags & PROTO_CMSG_DATA_ONLY))
> + if (!( sock->ops->flags & PROTO_CMSG_DATA_ONLY ||
extra space after "("
don't forget about brackets when mixing bitwise and logical and/or
It would look better if you'd get rid of outer brackets and propagate !
> __sys_whitelisted_cmsghdrs(msr) ))
> return -EINVAL;
> }
>
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 4+ messages in thread