drivers: can: socket: Use proper filter when setsockopt is called

Check that the received filter is can_filter type when setsockopt()
is called.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2019-03-08 17:44:07 +02:00 committed by Kumar Gala
commit fc36d56aca
2 changed files with 22 additions and 6 deletions

View file

@ -85,10 +85,7 @@ static inline int socket_can_setsockopt(struct device *dev, void *obj,
return -1; return -1;
} }
if (optlen != sizeof(struct can_filter)) { __ASSERT_NO_MSG(optlen == sizeof(struct zcan_filter));
errno = EINVAL;
return -1;
}
ret = can_attach_msgq(socket_context->can_dev, socket_context->msgq, ret = can_attach_msgq(socket_context->can_dev, socket_context->msgq,
optval); optval);

View file

@ -363,6 +363,15 @@ static int can_sock_setsockopt_vmeth(void *obj, int level, int optname,
struct net_if *iface; struct net_if *iface;
struct device *dev; struct device *dev;
/* The application must use can_filter and then we convert
* it to zcan_filter as the CANBUS drivers expects that.
*/
if (optname == CAN_RAW_FILTER &&
optlen != sizeof(struct can_filter)) {
errno = EINVAL;
return -1;
}
if (optval == NULL) { if (optval == NULL) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -377,8 +386,18 @@ static int can_sock_setsockopt_vmeth(void *obj, int level, int optname,
return -1; return -1;
} }
return api->setsockopt(dev, obj, level, optname, optval, if (optname == CAN_RAW_FILTER) {
optlen); struct zcan_filter zfilter;
can_copy_filter_to_zfilter((struct can_filter *)optval,
&zfilter);
return api->setsockopt(dev, obj, level, optname,
&zfilter, sizeof(zfilter));
}
return api->setsockopt(dev, obj, level, optname,
optval, optlen);
} }
return zcan_setsockopt_ctx(obj, level, optname, optval, optlen); return zcan_setsockopt_ctx(obj, level, optname, optval, optlen);