All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
To: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Richard Weinberger <richard@nod.at>,
	linux-can <linux-can@vger.kernel.org>
Subject: Re: PATCH: Breaking UAPI change?
Date: Thu, 25 Mar 2021 09:01:13 +0100	[thread overview]
Message-ID: <20210325080113.GA8446@x1.vandijck-laurijssen.be> (raw)
In-Reply-To: <26bf9711-9fe4-f7fe-22fe-750cf93bd760@hartkopp.net>

On Wed, 24 Mar 2021 21:26:19 +0100, Oliver Hartkopp wrote:
> On 24.03.21 20:27, Kurt Van Dijck wrote:
> >>----- Ursprüngliche Mail -----
> >>>>commit f5223e9eee65 ("can: extend sockaddr_can to include j1939 members")
> >commit 124900109ca88d29382ef2e2b848d3a2f9d67b98
> >Author: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
> >Date:   Wed Mar 24 20:08:50 2021
> >
> >     can raw: don't increase provided name length
> >     The length of the buffer is known by the application,
> >     not the kernel. Kernel is supposed to return only the
> >     size of used bytes.
> >     There is a minimum required size for the struct sockaddr_can
> >     to be usefull for can_raw, so errors are returned when
> >     the provided size is lower
> >     Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
> >
> >diff --git a/net/can/raw.c b/net/can/raw.c
> >index 6ec8aa1d0da4..00d352ae221e 100644
> >--- a/net/can/raw.c
> >+++ b/net/can/raw.c
> >@@ -475,7 +475,7 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
> >  	if (peer)
> >  		return -EOPNOTSUPP;
> >-	memset(addr, 0, sizeof(*addr));
> >+	memset(addr, 0, CAN_REQUIRED_SIZE(*addr, ifindex));
> >  	addr->can_family  = AF_CAN;
> >  	addr->can_ifindex = ro->ifindex;
> 
> Is there no need to adapt the return value then?
> 
> - return sizeof(*addr);
> + return CAN_REQUIRED_SIZE(*addr, ifindex);

indeed. I have missed that one.
I was looking for a function parameter, and then forgot somehow ...

> 
> Regards,
> Oliver
> 
> ps. If so, I need to go through isotp_getname() too ...
> 
> 
> >@@ -806,6 +806,10 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
> >  		return sock_recv_errqueue(sk, msg, size,
> >  					  SOL_CAN_RAW, SCM_CAN_RAW_ERRQUEUE);
> >+	if (msg->name && msg->msg_namelen <
> >+			CAN_REQUIRED_SIZE(struct sockaddr_can, ifindex))
> >+		return -EINVAL;
> >+
> >  	skb = skb_recv_datagram(sk, flags, noblock, &err);
> >  	if (!skb)
> >  		return err;
> >@@ -825,7 +829,8 @@ static int raw_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
> >  	if (msg->msg_name) {
> >  		__sockaddr_check_size(sizeof(struct sockaddr_can));
> >-		msg->msg_namelen = sizeof(struct sockaddr_can);
> >+		if (msg->msg_namelen > sizeof(struct sockaddr_can))
> >+			msg->msg_namelen = sizeof(struct sockaddr_can);
> >  		memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
> >  	}
> >

      parent reply	other threads:[~2021-03-25  8:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 15:30 Breaking UAPI change? Richard Weinberger
2021-03-24 19:01 ` Kurt Van Dijck
2021-03-24 19:21   ` Richard Weinberger
2021-03-24 19:27     ` PATCH: " Kurt Van Dijck
2021-03-24 19:47       ` Richard Weinberger
2021-03-24 20:26       ` Oliver Hartkopp
2021-03-24 21:59         ` Oliver Hartkopp
2021-03-25  8:01         ` Kurt Van Dijck [this message]

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=20210325080113.GA8446@x1.vandijck-laurijssen.be \
    --to=dev.kurt@vandijck-laurijssen.be \
    --cc=linux-can@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=socketcan@hartkopp.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.