virt: Add vboxguest driver for Virtual Box Guest integration
cover virt: Add vboxguest driver for Virtual Box Guest integration
Hi All,
Here is my first non RFC submission of my cleaned up version of the VirtualBox vboxguest driver.
VirtualBox upstream has declared the ioctl API for the /dev/vboxguest device as being stable now, so once this passes review this is ready for merging.
I'm only submitting the vboxguest driver for now, as the vboxsf driver depends on this and it easier to first just get the vboxguest driver upstream.
Here is (part of) the RFC v1 cover-letter which is still relevant:
I've removed all depenencies on vbox's OS-independent runtime and the runtime itself, reducing the vboxguest driver from 100000+ lines of code to aprox. 6200 lines. This reduces the non debug vboxguest.ko size from 450kB to less then 100 kB. I've also cleaned up various other warts such as doing hardware init in module_init rather then in a pci_probe callback.
The vboxguest driver introduces a new userspace API + ABI in the form of ioctls on a character device. VirtualBox upstream not willing to commit to keeping this ABI stable was one of the things which has kept this driver driver out of mainline sofar. I've been talking to VirtualBox upstream about mainlining the guest drivers and VirtualBox upstream has agreed to consider the userspace ABI stable and only extend it in a backwards compatible manner from now on.
Regards,
Hans
PATCH 1/1 virt: Add vboxguest driver for Virtual Box Guest integration
This commit adds a driver for the Virtual Box Guest PCI device used in Virtual Box virtual machines. Enabling this driver will add support for Virtual Box Guest integration features such as copy-and-paste, seamless mode and OpenGL pass-through.
This driver also offers vboxguest IPC functionality which is needed for the vboxfs driver which offers folder sharing support.
--- drivers/virt/Kconfig | 1 + drivers/virt/Makefile | 1 + drivers/virt/vboxguest/Kconfig | 16 + drivers/virt/vboxguest/Makefile | 3 + drivers/virt/vboxguest/vboxguest_core.c | 1666 ++++++++++++++++++++++++++ drivers/virt/vboxguest/vboxguest_core.h | 193 +++ drivers/virt/vboxguest/vboxguest_linux.c | 473 ++++++++ drivers/virt/vboxguest/vboxguest_utils.c | 1098 +++++++++++++++++ drivers/virt/vboxguest/vboxguest_version.h | 18 + include/linux/vbox_utils.h | 104 ++ include/linux/vbox_vmmdev.h | 123 ++ include/uapi/linux/vbox_err.h | 178 +++ include/uapi/linux/vbox_ostypes.h | 153 +++ include/uapi/linux/vbox_vmmdev.h | 1745 ++++++++++++++++++++++++++++ include/uapi/linux/vboxguest.h | 407 +++++++ 15 files changed, 6179 insertions(+) create mode 100644 drivers/virt/vboxguest/Kconfig create mode 100644 drivers/virt/vboxguest/Makefile create mode 100644 drivers/virt/vboxguest/vboxguest_core.c create mode 100644 drivers/virt/vboxguest/vboxguest_core.h create mode 100644 drivers/virt/vboxguest/vboxguest_linux.c create mode 100644 drivers/virt/vboxguest/vboxguest_utils.c create mode 100644 drivers/virt/vboxguest/vboxguest_version.h create mode 100644 include/linux/vbox_utils.h create mode 100644 include/linux/vbox_vmmdev.h create mode 100644 include/uapi/linux/vbox_err.h create mode 100644 include/uapi/linux/vbox_ostypes.h create mode 100644 include/uapi/linux/vbox_vmmdev.h create mode 100644 include/uapi/linux/vboxguest.h
drivers/virt/Kconfig +1 -0
@@ -30,4 +30,5 @@ config FSL_HV_MANAGER 4) A kernel interface for receiving callbacks when a managed partition shuts down. +source "drivers/virt/vboxguest/Kconfig" endif
drivers/virt/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_FSL_HV_MANAGER) += fsl_hypervisor.o +obj-y += vboxguest/
drivers/virt/vboxguest/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +config VBOXGUEST + tristate "Virtual Box Guest integration support" + depends on X86 && PCI && INPUT + help + This is a driver for the Virtual Box Guest PCI device used in + Virtual Box virtual machines. Enabling this driver will add + support for Virtual Box Guest integration features such as + copy-and-paste, seamless mode and OpenGL pass-through. + + This driver also offers vboxguest IPC functionality which is needed + for the vboxfs driver which offers folder sharing support. + + Although it is possible to build this module in, it is advised + to build this driver as a module, so that it can be updated + independently of the kernel. Select M to build this driver as a + module.
drivers/virt/vboxguest/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +vboxguest-y := vboxguest_linux.o vboxguest_core.o vboxguest_utils.o + +obj-$(CONFIG_VBOXGUEST) += vboxguest.o
drivers/virt/vboxguest/vboxguest_core.c new file +1666 -0
1,666 lines not on this page · raw message
drivers/virt/vboxguest/vboxguest_core.h new file +193 -0
193 lines not on this page · raw message
drivers/virt/vboxguest/vboxguest_linux.c new file +473 -0
473 lines not on this page · raw message
drivers/virt/vboxguest/vboxguest_utils.c new file +1098 -0
640 lines not on this page · raw message
drivers/virt/vboxguest/vboxguest_version.h new file +18 -0
Lines of this file are not shown. View the raw message.
include/linux/vbox_utils.h new file +104 -0
104 lines not on this page · raw message
include/linux/vbox_vmmdev.h new file +123 -0
123 lines not on this page · raw message
include/uapi/linux/vbox_err.h new file +178 -0
178 lines not on this page · raw message
include/uapi/linux/vbox_ostypes.h new file +153 -0
153 lines not on this page · raw message
include/uapi/linux/vbox_vmmdev.h new file +1745 -0
1,745 lines not on this page · raw message
include/uapi/linux/vboxguest.h new file +407 -0
407 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.14.2
Part of the diff is not shown here. View the raw message.
Looks like you forgot to CC previous revierers.
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)
It seems like you ignored the comments on the last version.
Get rid of the weird struct capilization.
Make these things functions instead of macros.
drivers/virt/vboxguest/vboxguest_core.c line 68
Quoted 2 lines
drivers/virt/vboxguest/vboxguest_core.c new file +2
-0+VMMDevReqHypervisorInfo *req; +void *guest_mappings[GUEST_MAPPINGS_TRIES ];
Fix your structure names.
drivers/virt/vboxguest/vboxguest_core.c line 103
Quoted 1 line
drivers/virt/vboxguest/vboxguest_core.c new file +1
-0+for (i =0 ; i < (size >>PAGE_SHIFT ); i++)
Remove pointless inner braces.
drivers/virt/vboxguest/vboxguest_core.c line 206
Quoted 5 lines
drivers/virt/vboxguest/vboxguest_core.c new file +5
-0+#ifdef CONFIG_X86_64 + req1->guestInfo.osType = VBOXOSTYPE_Linux26_x64; +#else + req1->guestInfo.osType = VBOXOSTYPE_Linux26; +#endif
Hardcoding architecvtures is almost always a bug. If you think it isn't here it needs a big fat comment explaining that rationale.
drivers/virt/vboxguest/vboxguest_core.c line 262
Quoted 2 lines
drivers/virt/vboxguest/vboxguest_core.c new file +2
-0+ req->guestStatus.status = active ? VBoxGuestFacilityStatus_Active : + VBoxGuestFacilityStatus_Inactive;
Please use if/else for readability.
Quoted 3 lines
+/** @name Memory Ballooning
+ * @{
+ */
Please get rid of this whacky comment style.
drivers/virt/vboxguest/vboxguest_core.c line 286
Quoted 10 lines
drivers/virt/vboxguest/vboxguest_core.c new file +10
-0+ +/** +* Inflate the balloon by one chunk. +* +* The caller owns the balloon mutex. +* +* @returns 0 or negative errno value. +* @param gdev The Guest extension device. +* @param chunk_idx Index of the chunk. +*/
An this one isn't proper kerneldoc either.
drivers/virt/vboxguest/vboxguest_core.c line 339
Quoted 5 lines
drivers/virt/vboxguest/vboxguest_core.c new file +4
-0+ pages = kmalloc(sizeof(*pages) * VMMDEV_MEMORY_BALLOON_CHUNK_PAGES, +/** +* Callback for heartbeat timer. +*/
/**
as the comment start is reserved for kerneldoc comments, this one isn't a kerneldoc comment, so please remove it.
drivers/virt/vboxguest/vboxguest_core.c line 448
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c new file +8
-0+static void vbg_heartbeat_timer (unsigned long data) +{ +struct vbg_dev *gdev = (struct vbg_dev *)data; + +vbg_req_perform (gdev, gdev->guest_heartbeat_req); +mod_timer (&gdev->heartbeat_timer, +msecs_to_jiffies (gdev->heartbeat_interval_ms)); +}
Please use timer_setup and from_timer instead of the data argument. (this is new in -rc3).
Review
Quoted 2 lines
(quoted diff) +2
-0+ list_add(&session->list_node, &gdev->session_list); + spin_unlock_irqrestore(&gdev->session_spinlock, flags);
Session_list isn't used anywhere. And if it was it would probably buggy due to the lack of reference counting.
drivers/virt/vboxguest/vboxguest_core.c line 974
Quoted 4 lines
drivers/virt/vboxguest/vboxguest_core.c new file +4
-0+ + *session_ret = session; + +return 0 ;
Just return the session or an ERR_PTR.
drivers/virt/vboxguest/vboxguest_core.c line 1197
Quoted 1 line
drivers/virt/vboxguest/vboxguest_core.c new file +1
-0+ guest_status = (const VMMDevReportGuestStatus *)req;
struct pointer asts are a ba idea - this probably should use container_of magic or a more generic strucure with unioned elements.
drivers/virt/vboxguest/vboxguest_utils.c line 1026
Quoted 7 lines
drivers/virt/vboxguest/vboxguest_utils.c new file +7
-0+int vbg_status_code_to_errno (int rc) +{ +if (rc >=0 ) +return 0 ; + +switch (rc) { +case VERR_ACCESS_DENIED :return -EPERM ;
Please never put code in the same line as the switch statement.
Also in general code like this is better done by looping over a lookup table.
Anyway, this was a super shallow review that everyone could do.
The actual ioctls and pv hardware interfaces look even worse, but such a messy giant blob they aren't reviewable. This patch needs a major cleanup pass first, and then a split into reviewable chunks.
Hi,
Quoted 11 lines · Christoph Hellwig
Looks like you forgot to CC previous revierers.
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)It seems like you ignored the comments on the last version.
Quoted 1 line
Get rid of the weird struct capilization.
The only capitalized structs are all from headers under include/uapi, I can remove the capitalization without breaking the ABI, but if I do that the VirtualBox Guest Additions userspace will no longer be able to actually be compiled against the in kernel version of the headers which seems undesirable.
Arnd, Greg KH, what is your opinion about this? I would like to be able to actually compile the userspace consumer of this API against the in kernel headers, I can change the struct names (and drop the typedefs) if that is considered something which I MUST fix to get this in mainline, but I would rather keep things so that the userspace tools can be compiled against the in kernel uapi headers.
Quoted 1 line
Make these things functions instead of macros.
Turning these into functions is a good idea I will do so for v2.
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c line 68
Quoted 2 lines
drivers/virt/vboxguest/vboxguest_core.c new file +2
-0+VMMDevReqHypervisorInfo *req; +void *guest_mappings[GUEST_MAPPINGS_TRIES ];Fix your structure names.
drivers/virt/vboxguest/vboxguest_core.c line 103
Quoted 1 line
drivers/virt/vboxguest/vboxguest_core.c new file +1
-0+for (i =0 ; i < (size >>PAGE_SHIFT ); i++)Remove pointless inner braces.
One person's pointless braces are another person's way to improve code readability. Using braces around one of the 2 operands of a "<" operation is quite a normal thing to do.
Quoted 85 lines
drivers/virt/vboxguest/vboxguest_core.c line 206
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +5
-0+#ifdef CONFIG_X86_64 + req1->guestInfo.osType = VBOXOSTYPE_Linux26_x64; +#else + req1->guestInfo.osType = VBOXOSTYPE_Linux26; +#endif Hardcoding architecvtures is almost always a bug. If you think it isn't here it needs a big fat comment explaining that rationale.
drivers/virt/vboxguest/vboxguest_core.c line 262
Quoted 2 lines
drivers/virt/vboxguest/vboxguest_core.c new file +2
-0+ req->guestStatus.status = active ? VBoxGuestFacilityStatus_Active : + VBoxGuestFacilityStatus_Inactive;Please use if/else for readability.
Quoted 3 lines
+/** @name Memory Ballooning
+ * @{
+ */Please get rid of this whacky comment style.
drivers/virt/vboxguest/vboxguest_core.c line 286
Quoted 10 lines
drivers/virt/vboxguest/vboxguest_core.c new file +10
-0+ +/** +* Inflate the balloon by one chunk. +* +* The caller owns the balloon mutex. +* +* @returns 0 or negative errno value. +* @param gdev The Guest extension device. +* @param chunk_idx Index of the chunk. +*/ An this one isn't proper kerneldoc either.
drivers/virt/vboxguest/vboxguest_core.c line 339
Quoted 5 lines
drivers/virt/vboxguest/vboxguest_core.c new file +4
-0+ pages = kmalloc(sizeof(*pages) * VMMDEV_MEMORY_BALLOON_CHUNK_PAGES, +/** +* Callback for heartbeat timer. +*/ /**
as the comment start is reserved for kerneldoc comments, this one isn't a kerneldoc comment, so please remove it.
drivers/virt/vboxguest/vboxguest_core.c line 448
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c new file +8
-0+static void vbg_heartbeat_timer (unsigned long data) +{ +struct vbg_dev *gdev = (struct vbg_dev *)data; + +vbg_req_perform (gdev, gdev->guest_heartbeat_req); +mod_timer (&gdev->heartbeat_timer, +msecs_to_jiffies (gdev->heartbeat_interval_ms)); +}Please use
timer_setupandfrom_timerinstead of the data argument. (this is new in -rc3).Review
Quoted 2 lines
(quoted diff) +2
-0+ list_add(&session->list_node, &gdev->session_list); + spin_unlock_irqrestore(&gdev->session_spinlock, flags);
Session_listisn't used anywhere. And if it was it would probably buggy due to the lack of reference counting.drivers/virt/vboxguest/vboxguest_core.c line 974
Quoted 4 lines
drivers/virt/vboxguest/vboxguest_core.c new file +4
-0+ + *session_ret = session; + +return 0 ;Just return the session or an
ERR_PTR.drivers/virt/vboxguest/vboxguest_core.c line 1197
Quoted 1 line
drivers/virt/vboxguest/vboxguest_core.c new file +1
-0+ guest_status = (const VMMDevReportGuestStatus *)req;struct pointer asts are a ba idea - this probably should use
container_ofmagic or a more generic strucure with unioned elements.drivers/virt/vboxguest/vboxguest_utils.c line 1026
Quoted 7 lines
drivers/virt/vboxguest/vboxguest_utils.c new file +7
-0+int vbg_status_code_to_errno (int rc) +{ +if (rc >=0 ) +return 0 ; + +switch (rc) { +case VERR_ACCESS_DENIED :return -EPERM ;Please never put code in the same line as the switch statement.
Quoted 4 lines
Also in general code like this is better done by looping over a lookup table.
Anyway, this was a super shallow review that everyone could do.
Thank you for your review, I will try to address most of your remarks for v2 of this patch.
Quoted 3 lines
The actual ioctls and pv hardware interfaces look even worse, but such a messy giant blob they aren't reviewable. This patch needs a major cleanup pass first, and then a split into reviewable chunks.
This patch adds a single driver, so there is no sensible way to split it up.
As for the pv interface that is part of existing deployed (virtual) hardware, we can pretty much change that just as much as we can change the hardware-interface of real hardware.
Regards,
Hans
Greg Kroah-Hartman
maintainerQuoted 22 lines · Hans de Goede
Hi,
Quoted 11 lines · Christoph Hellwig
Looks like you forgot to CC previous revierers.
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)It seems like you ignored the comments on the last version.
Quoted 1 line
Get rid of the weird struct capilization.
The only capitalized structs are all from headers under
include/uapi, I can remove the capitalization without breaking the ABI, but if I do that the VirtualBox Guest Additions userspace will no longer be able to actually be compiled against the in kernel version of the headers which seems undesirable.
Quoted 7 lines
Arnd, Greg KH, what is your opinion about this? I would like to be able to actually compile the userspace consumer of this API against the in kernel headers, I can change the struct names (and drop the typedefs) if that is considered something which I MUST fix to get this in mainline, but I would rather keep things so that the userspace tools can be compiled against the in kernel uapi headers.
My opinion is that kernel code, including headers, needs to look like kernel code. None of this "but this single, tiny, driver is special and unique and gets to keep its bizarre coding style" stuff. The longevity of the developer community and codebase precludes that kind of "special treatment".
And if userspace _really_ likes typedefs, then it's trivial for them to just have something like a list of:
typedef struct virtual_box_check_ballon VBGLIOCCHECKBALLOON, *PVBGLIOCCHECKBALLOON;
in their .h file that they use after they include these uapi headers.
Remember, our coding style rules are there for a good reason, you want others to fix, maintain, and understand the code, for a long time. It's not just there because we like to be mean. It's your brain we care about :)
So it should be fixed up.
Quoted 2 lines
This patch adds a single driver, so there is no sensible way to split it up.
It's 6k lines, split it at least by the file level, can you read this all in one sitting?
try something like:
- uapi header files
- util functions
- "linux" core
- rest
or something like that. Be considerate of those who have to read this stuff, you _want_ us to be happy to do so...
As it is, I'm not even going to look at it, it's too big, sorry.
thanks,
greg k-h
Hi,
Quoted 42 lines · Greg Kroah-Hartman
Quoted 22 lines · Hans de Goede
Hi,
Quoted 11 lines · Christoph Hellwig
Looks like you forgot to CC previous revierers.
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)It seems like you ignored the comments on the last version.
Quoted 1 line
Get rid of the weird struct capilization.
The only capitalized structs are all from headers under
include/uapi, I can remove the capitalization without breaking the ABI, but if I do that the VirtualBox Guest Additions userspace will no longer be able to actually be compiled against the in kernel version of the headers which seems undesirable.Quoted 7 lines
Arnd, Greg KH, what is your opinion about this? I would like to be able to actually compile the userspace consumer of this API against the in kernel headers, I can change the struct names (and drop the typedefs) if that is considered something which I MUST fix to get this in mainline, but I would rather keep things so that the userspace tools can be compiled against the in kernel uapi headers.
My opinion is that kernel code, including headers, needs to look like kernel code. None of this "but this single, tiny, driver is special and unique and gets to keep its bizarre coding style" stuff. The longevity of the developer community and codebase precludes that kind of "special treatment".
And if userspace _really_ likes typedefs, then it's trivial for them to just have something like a list of:
typedef struct
virtual_box_check_ballonVBGLIOCCHECKBALLOON, *PVBGLIOCCHECKBALLOON;
Quoted 8 lines
in their .h file that they use after they include these uapi headers.
Remember, our coding style rules are there for a good reason, you want others to fix, maintain, and understand the code, for a long time. It's not just there because we like to be mean. It's your brain we care about :)
So it should be fixed up.
Ok, will fix for v2.
Quoted 6 lines
Quoted 2 lines
This patch adds a single driver, so there is no sensible way to split it up.
It's 6k lines, split it at least by the file level, can you read this all in one sitting?
Quoted 7 lines
try something like:
- uapi header files
- util functions
- "linux" core
- rest
or something like that. Be considerate of those who have to read this stuff, you _want_ us to be happy to do so...
Ok, I will split this up for v2.
Regards,
Hans
Hi,
On 03-10-17 13:41, Hans de Goede wrote:
<snip>
Quoted 10 lines
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)Make these things functions instead of macros.
Turning these into functions is a good idea I will do so for v2.
Correction, I forgot that the passed in "req" macro argument has a different type with all the calls, so these cannot be changed into functions because they rely on sizeof on the specific type to do the size checks.
Regards,
Hans
Greg Kroah-Hartman
maintainerQuoted 15 lines · Hans de Goede
Hi,
On 03-10-17 13:41, Hans de Goede wrote:
<snip>
Quoted 9 lines
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)Make these things functions instead of macros.
Quoted 7 lines
Quoted 1 line
Turning these into functions is a good idea I will do so for v2.
Correction, I forgot that the passed in "req" macro argument has a different type with all the calls, so these cannot be changed into functions because they rely on sizeof on the specific type to do the size checks.
Don't we already have built-in checks for these types of things? Surely we don't require each ioctl user in the kernel to do this by themselves...
thanks,
greg k-h
Arnd Bergmann
maintainerQuoted 24 lines · Greg Kroah-Hartman
Quoted 15 lines · Hans de Goede
Hi,
On 03-10-17 13:41, Hans de Goede wrote:
<snip>
Quoted 9 lines
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)Make these things functions instead of macros.
Quoted 7 lines
Quoted 1 line
Turning these into functions is a good idea I will do so for v2.
Correction, I forgot that the passed in "req" macro argument has a different type with all the calls, so these cannot be changed into functions because they rely on sizeof on the specific type to do the size checks.
Quoted 3 lines
Don't we already have built-in checks for these types of things? Surely we don't require each ioctl user in the kernel to do this by themselves...
No other driver uses this kind of header for the ioctl structures, usually we just rely on the ioctl command number to encode the size, or we copy a fixed length.
Arnd
Greg Kroah-Hartman
maintainerQuoted 26 lines · Arnd Bergmann
Quoted 24 lines · Greg Kroah-Hartman
Quoted 22 lines · Hans de Goede
Hi,
On 03-10-17 13:41, Hans de Goede wrote:
<snip>
Quoted 10 lines
Quoted 8 lines
drivers/virt/vboxguest/vboxguest_core.c line 35
Quoted 6 lines
drivers/virt/vboxguest/vboxguest_core.c new file +6
-0+#define CHECK_IOCTL_IN (req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)Make these things functions instead of macros.
Turning these into functions is a good idea I will do so for v2.
Correction, I forgot that the passed in "req" macro argument has a different type with all the calls, so these cannot be changed into functions because they rely on sizeof on the specific type to do the size checks.
Quoted 7 lines
Quoted 3 lines
Don't we already have built-in checks for these types of things? Surely we don't require each ioctl user in the kernel to do this by themselves...
No other driver uses this kind of header for the ioctl structures, usually we just rely on the ioctl command number to encode the size, or we copy a fixed length.
Then why can't we do the same thing here as well?
Hi,
Quoted 31 lines · Greg Kroah-Hartman
Quoted 30 lines · Arnd Bergmann
Quoted 27 lines · Greg Kroah-Hartman
Quoted 15 lines · Hans de Goede
Hi,
On 03-10-17 13:41, Hans de Goede wrote:
<snip>
Quoted 9 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+#define CHECK_IOCTL_IN(req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)Make these things functions instead of macros.
Quoted 7 lines
Quoted 1 line
Turning these into functions is a good idea I will do so for v2.
Correction, I forgot that the passed in "req" macro argument has a different type with all the calls, so these cannot be changed into functions because they rely on sizeof on the specific type to do the size checks.
Don't we already have built-in checks for these types of things? Surely we don't require each ioctl user in the kernel to do this by themselves...
Quoted 5 lines
Quoted 3 lines
No other driver uses this kind of header for the ioctl structures, usually we just rely on the ioctl command number to encode the size, or we copy a fixed length.
Then why can't we do the same thing here as well?
VirtualBox uses the same ioctl interface for the guest-additions userspace parts on all supported platforms and not all platforms support encoding the size in the ioctl number, so all the ioctl data structs have a header with the in and out sizes in there, these macros check that header.
As mentioned during the RFC discussions changing the ioctl interface is going to be troublesome to do because we want to be ABI compatible with the kernel module shipped with the guest additions.
Having 2 separate guest additions builds, one for running with the out of tree driver (which eventually should go away I hope, but certainly not soon) and another build for the mainline version of the vboxguest driver is not supportable.
I'm confident that if we find issues during the review process, which have security implications, or where behavior is not clearly specified, that we can get VirtualBox upstream to fix the API for that, but outright re-designing the API is not really an option I believe.
As for these specific macros to check the ioctl data struct header, if these are considered a problem I can simply write out the code in the few places where this macro is called.
Regards,
Hans
Greg Kroah-Hartman
maintainerQuoted 54 lines · Hans de Goede
Hi,
Quoted 31 lines · Greg Kroah-Hartman
Quoted 30 lines · Arnd Bergmann
Quoted 27 lines · Greg Kroah-Hartman
Quoted 15 lines · Hans de Goede
Hi,
On 03-10-17 13:41, Hans de Goede wrote:
<snip>
Quoted 9 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+#define CHECK_IOCTL_IN(req) \ +do { \ + if ((req)->Hdr.cbIn != (sizeof((req)->Hdr) + sizeof((req)->u.In)) || \ + (req)->Hdr.cbOut != sizeof((req)->Hdr)) \ + return -EINVAL; \ +} while (0)Make these things functions instead of macros.
Quoted 7 lines
Quoted 1 line
Turning these into functions is a good idea I will do so for v2.
Correction, I forgot that the passed in "req" macro argument has a different type with all the calls, so these cannot be changed into functions because they rely on sizeof on the specific type to do the size checks.
Don't we already have built-in checks for these types of things? Surely we don't require each ioctl user in the kernel to do this by themselves...
Quoted 5 lines
Quoted 3 lines
No other driver uses this kind of header for the ioctl structures, usually we just rely on the ioctl command number to encode the size, or we copy a fixed length.
Then why can't we do the same thing here as well?
VirtualBox uses the same ioctl interface for the guest-additions userspace parts on all supported platforms and not all platforms support encoding the size in the ioctl number, so all the ioctl data structs have a header with the in and out sizes in there, these macros check that header.
As mentioned during the RFC discussions changing the ioctl interface is going to be troublesome to do because we want to be ABI compatible with the kernel module shipped with the guest additions.
Having 2 separate guest additions builds, one for running with the out of tree driver (which eventually should go away I hope, but certainly not soon) and another build for the mainline version of the vboxguest driver is not supportable.
Quoted 8 lines
I'm confident that if we find issues during the review process, which have security implications, or where behavior is not clearly specified, that we can get VirtualBox upstream to fix the API for that, but outright re-designing the API is not really an option I believe.
As for these specific macros to check the ioctl data struct header, if these are considered a problem I can simply write out the code in the few places where this macro is called.
Ok, that makes a bit more sense, let's see what your next round of patches look like, we can take it from there :)
thanks,
greg k-h