fixing the rtcan_raw ioctl argument issue
We have a problem with CAN control requests piggybacking on struct ifreq for passing arguments to the raw driver. This is unsafe, since we have no mean to relate sizeof(ifr.ifr_ifru) to the actual size required to pass the CAN-related arguments to the ioctl handler, so we are currently hopping for the best.
In addition, all rtcan utilities are causing recent compilers here to complain loudly about potential aliasing issues when mapping those arguments over the ifr_ifru area using casts, which is unfortunately true.
So I came up with a general fix, introducing struct can_ifreq for this purpose. Applications passing struct ifreq should still work (well, that is the plan) since sizeof(struct ifreq) >= sizeof(struct can_ifreq) and all member offsets within ifr_ifru have been preserved. Could the CAN maintainers please review this code and comment?
Thanks,
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=5460e09d0f990799fb2eed67fbb00358860ebcab
Signature · 1 line
Philippe.
Hi Philippe,
Am 04.09.2015 um 18:18 schrieb Philippe Gerum:
Quoted 17 lines
We have a problem with CAN control requests piggybacking on struct ifreq for passing arguments to the raw driver. This is unsafe, since we have no mean to relate
sizeof(ifr.ifr_ifru)to the actual size required to pass the CAN-related arguments to the ioctl handler, so we are currently hopping for the best.In addition, all rtcan utilities are causing recent compilers here to complain loudly about potential aliasing issues when mapping those arguments over the
ifr_ifruarea using casts, which is unfortunately true.So I came up with a general fix, introducing struct
can_ifreqfor this purpose. Applications passing struct ifreq should still work (well, that is the plan) since sizeof(struct ifreq) >=sizeof(struct can_ifreq)and all member offsets withinifr_ifruhave been preserved. Could the CAN maintainers please review this code and comment?
Quoted 3 lines
Thanks,
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=5460e09d0f990799fb2eed67fbb00358860ebcab
Looks good at a first glance and you fixed a repeated patterns as well. Just "demo/posix/can_rtt.c" should be adapted as well. Has it been tested on real CAN hardware? Unfortunately, I currently do not have usable CAN hardware at hand to do it myself, sorry.
Thanks,
Wolfgang.
Hi Wolfgang,
Quoted 21 lines · Wolfgang Grandegger
Hi Philippe,
Am 04.09.2015 um 18:18 schrieb Philippe Gerum:
Quoted 18 lines
We have a problem with CAN control requests piggybacking on struct ifreq for passing arguments to the raw driver. This is unsafe, since we have no mean to relate
sizeof(ifr.ifr_ifru)to the actual size required to pass the CAN-related arguments to the ioctl handler, so we are currently hopping for the best.In addition, all rtcan utilities are causing recent compilers here to complain loudly about potential aliasing issues when mapping those arguments over the
ifr_ifruarea using casts, which is unfortunately true.So I came up with a general fix, introducing struct
can_ifreqfor this purpose. Applications passing struct ifreq should still work (well, that is the plan) since sizeof(struct ifreq) >=sizeof(struct can_ifreq)and all member offsets withinifr_ifruhave been preserved. Could the CAN maintainers please review this code and comment?
Quoted 7 lines
Quoted 4 lines
Thanks,
http://git.xenomai.org/xenomai-3.git/commit/?h=next&id=5460e09d0f990799fb2eed67fbb00358860ebcab
Looks good at a first glance and you fixed a repeated patterns as well. Just "
demo/posix/can_rtt.c" should be adapted as well. Has it been
Ok.
Quoted 3 lines
tested on real CAN hardware? Unfortunately, I currently do not have usable CAN hardware at hand to do it myself, sorry.
I will test this on imx6q flexcan hardware.
Signature · 1 line
Philippe.