* [PATCH] can: test size of struct sockaddr @ 2011-01-14 17:23 Kurt Van Dijck [not found] ` <20110114172321.GB331-MxZ6Iy/zr/UdbCeoMzGj59i2O/JbrIOy@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Kurt Van Dijck @ 2011-01-14 17:23 UTC (permalink / raw) To: netdev-u79uwXL29TY76Z2rM5mHXA, socketcan-core-0fE9KPoRgkgATYTw5x5z8w I think this patch makes the CAN socket code comform to the manpages of sendmsg & recvmsg. Signed-off-by: Kurt Van Dijck <kurt.van.dijck-/BeEPy95v10@public.gmane.org> --- net/can/bcm.c | 6 +++++- net/can/raw.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/net/can/bcm.c b/net/can/bcm.c index 6faa825..dc0d5d6 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -1256,6 +1256,9 @@ static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock, struct sockaddr_can *addr = (struct sockaddr_can *)msg->msg_name; + if (msg->msg_namelen < sizeof(*addr)) + return -EINVAL; + if (addr->can_family != AF_CAN) return -EINVAL; @@ -1557,8 +1560,9 @@ static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock, sock_recv_ts_and_drops(msg, sk, skb); if (msg->msg_name) { + memcpy(msg->msg_name, skb->cb, MIN(msg->msg_namelen, + sizeof(struct sockaddr_can))); msg->msg_namelen = sizeof(struct sockaddr_can); - memcpy(msg->msg_name, skb->cb, msg->msg_namelen); } skb_free_datagram(sk, skb); diff --git a/net/can/raw.c b/net/can/raw.c index e88f610..e68a6d3 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -649,6 +649,9 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock, struct sockaddr_can *addr = (struct sockaddr_can *)msg->msg_name; + if (msg->msg_namelen < sizeof(*addr)) + return -EINVAL; + if (addr->can_family != AF_CAN) return -EINVAL; @@ -727,8 +730,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock, sock_recv_ts_and_drops(msg, sk, skb); if (msg->msg_name) { + memcpy(msg->msg_name, skb->cb, MIN(msg->msg_namelen, + sizeof(struct sockaddr_can))); msg->msg_namelen = sizeof(struct sockaddr_can); - memcpy(msg->msg_name, skb->cb, msg->msg_namelen); } /* assign the flags that have been recorded in raw_rcv() */ ^ permalink raw reply related [flat|nested] 3+ messages in thread
[parent not found: <20110114172321.GB331-MxZ6Iy/zr/UdbCeoMzGj59i2O/JbrIOy@public.gmane.org>]
* Re: [PATCH] can: test size of struct sockaddr [not found] ` <20110114172321.GB331-MxZ6Iy/zr/UdbCeoMzGj59i2O/JbrIOy@public.gmane.org> @ 2011-01-15 17:08 ` Oliver Hartkopp [not found] ` <4D31D4A6.4040701-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Oliver Hartkopp @ 2011-01-15 17:08 UTC (permalink / raw) To: Kurt Van Dijck Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, netdev-u79uwXL29TY76Z2rM5mHXA On 14.01.2011 18:23, Kurt Van Dijck wrote: > I think this patch makes the CAN socket code comform to the > manpages of sendmsg & recvmsg. Hello Kurt, if you check similar code sniplets in the kernel you would see, that in recvmsg()-cases the given namelen is not used from userspace. If msg->msg_name is not NULL the msg_namelen is just set by the kernel. E.g. see af_packet.c, af_econet.c, etc. So the code in candump.c setting the msg_namelen before recvmsg() is obviously obsolete ... Btw. your two patches below for bcm_sendmsg() and raw_sendmesg() look good. If you would like to resubmit these two patches, you may add my Acked-by Thanks, Oliver > diff --git a/net/can/bcm.c b/net/can/bcm.c > index 6faa825..dc0d5d6 100644 > --- a/net/can/bcm.c > +++ b/net/can/bcm.c > @@ -1256,6 +1256,9 @@ static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock, > struct sockaddr_can *addr = > (struct sockaddr_can *)msg->msg_name; > > + if (msg->msg_namelen < sizeof(*addr)) > + return -EINVAL; > + > if (addr->can_family != AF_CAN) > return -EINVAL; > > diff --git a/net/can/raw.c b/net/can/raw.c > index e88f610..e68a6d3 100644 > --- a/net/can/raw.c > +++ b/net/can/raw.c > @@ -649,6 +649,9 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock, > struct sockaddr_can *addr = > (struct sockaddr_can *)msg->msg_name; > > + if (msg->msg_namelen < sizeof(*addr)) > + return -EINVAL; > + > if (addr->can_family != AF_CAN) > return -EINVAL; > ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <4D31D4A6.4040701-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>]
* Re: [PATCH] can: test size of struct sockaddr [not found] ` <4D31D4A6.4040701-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org> @ 2011-01-15 19:35 ` Kurt Van Dijck 0 siblings, 0 replies; 3+ messages in thread From: Kurt Van Dijck @ 2011-01-15 19:35 UTC (permalink / raw) To: Oliver Hartkopp Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, netdev-u79uwXL29TY76Z2rM5mHXA On Sat, Jan 15, 2011 at 06:08:54PM +0100, Oliver Hartkopp wrote: > On 14.01.2011 18:23, Kurt Van Dijck wrote: > > I think this patch makes the CAN socket code comform to the > > manpages of sendmsg & recvmsg. > > Hello Kurt, > > if you check similar code sniplets in the kernel you would see, that in > recvmsg()-cases the given namelen is not used from userspace. I went into udp code, but my mind got troubled there. > > If msg->msg_name is not NULL the msg_namelen is just set by the kernel. E.g. > see af_packet.c, af_econet.c, etc. I should have looked further ... Given this, I went up to net/socket.c:__sys_recvmsg. Within kernel space, a struct sockaddr_storage is used in fact .... This solves indeed the problem I was trying to address. > > So the code in candump.c setting the msg_namelen before recvmsg() is obviously > obsolete ... I think no, since after the socket's recvmsg() has been called, since move_addr_to_user() will do checks similar as I tried to reimplement. > > Btw. your two patches below for bcm_sendmsg() and raw_sendmesg() look good. > > If you would like to resubmit these two patches, you may add my Acked-by Thanks, I will do so. Kurt ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-15 19:35 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-01-14 17:23 [PATCH] can: test size of struct sockaddr Kurt Van Dijck [not found] ` <20110114172321.GB331-MxZ6Iy/zr/UdbCeoMzGj59i2O/JbrIOy@public.gmane.org> 2011-01-15 17:08 ` Oliver Hartkopp [not found] ` <4D31D4A6.4040701-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org> 2011-01-15 19:35 ` Kurt Van Dijck
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).