netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Donald Hunter <donald.hunter@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	donald.hunter@redhat.com
Subject: Re: [PATCH net-next v1] rtnetlink: Return error when message too short
Date: Mon, 20 Mar 2023 20:18:08 -0700	[thread overview]
Message-ID: <20230320201808.6cc362b2@kernel.org> (raw)
In-Reply-To: <20230320231834.66273-1-donald.hunter@gmail.com>

On Mon, 20 Mar 2023 23:18:34 +0000 Donald Hunter wrote:
> rtnetlink_rcv_msg currently returns 0 when the message length is too
> short. This leads to either no response at all, or an ack response
> if NLM_F_ACK was set in the request.
> 
> Change rtnetlink_rcv_msg to return -EINVAL which tells af_netlink to
> generate a proper error response.

It's a touch risky to start returning an error now.
Some application could possibly have been passing an empty netlink
message just because.

We should give the user a heads up (pr_warn_once() with the name+pid
of current process). Or continue returning a 0 but add a warning via 
the extack. The latter is cleaner but will not help old / sloppy apps,
your call.

> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

We can't put a Fixes tag on it. It could break uAPI, we don't want 
it backported for sure.

> Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
> ---
>  net/core/rtnetlink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 5d8eb57867a9..04b7f184f32e 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -6086,7 +6086,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
>  
>  	/* All the messages must have at least 1 byte length */
>  	if (nlmsg_len(nlh) < sizeof(struct rtgenmsg))
> -		return 0;
> +		return -EINVAL;
>  
>  	family = ((struct rtgenmsg *)nlmsg_data(nlh))->rtgen_family;
>  	kind = rtnl_msgtype_kind(type);


  reply	other threads:[~2023-03-21  3:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 23:18 [PATCH net-next v1] rtnetlink: Return error when message too short Donald Hunter
2023-03-21  3:18 ` Jakub Kicinski [this message]
2023-03-21 10:04   ` Donald Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230320201808.6cc362b2@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=donald.hunter@redhat.com \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).