linux-user: fix kpartx ioctl problems
cover linux-user: fix kpartx ioctl problems
This patchset fixes a couple of ioctl bugs which were causing problems with running kpartx:
(1) add the missing ioctls for the loop-control device
(2) fix the BLKSSZGET ioctl not to trash memory on 64-bit guests
Peter Maydell (2):
linux-user: Add loop control ioctls
linux-user: Correct type for BLKSSZGET
linux-user/ioctls.h | 6 +++++- linux-user/linux_loop.h | 11 ++++++++++- linux-user/syscall_defs.h | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 linux-user: Add loop control ioctls
Add support for the /dev/loop-control ioctls:
LOOP_CTL_ADD
LOOP_CTL_REMOVE
LOOP_CTL_GET_FREE
--- linux-user/ioctls.h | 4 ++++ linux-user/linux_loop.h | 11 ++++++++++- linux-user/syscall_defs.h | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-)
linux-user/ioctls.h +4 -0
@@ -356,6 +356,10 @@ IOCTL(LOOP_GET_STATUS64, IOC_W, MK_PTR(MK_STRUCT(STRUCT_loop_info64))) IOCTL(LOOP_CHANGE_FD, 0, TYPE_INT) + IOCTL(LOOP_CTL_ADD, 0, TYPE_INT) + IOCTL(LOOP_CTL_REMOVE, 0, TYPE_INT) + IOCTL(LOOP_CTL_GET_FREE, 0, TYPE_NULL) + IOCTL(MTIOCTOP, IOC_W, MK_PTR(MK_STRUCT(STRUCT_mtop))) IOCTL(MTIOCGET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_mtget)))IOCTL (MTIOCPOS ,IOC_R ,MK_PTR (MK_STRUCT (STRUCT_mtpos)))
linux-user/linux_loop.h +10 -1
@@ -1,4 +1,6 @@ -/* Copied from 2.6.25 kernel headers to avoid problems on older hosts. */ +/* Copied from 2.6.25 kernel headers to avoid problems on older hosts, +* and subsequently updated to match newer additions to the API. +*/ #ifndef _LINUX_LOOP_H#define _LINUX_LOOP_H
@@ -91,5 +93,12 @@ struct loop_info64 {#define LOOP_SET_STATUS64 0x4C04#define LOOP_GET_STATUS64 0x4C05#define LOOP_CHANGE_FD 0x4C06 +#define LOOP_SET_CAPACITY 0x4C07 +#define LOOP_SET_DIRECT_IO 0x4C08 + +/* /dev/loop-control interface */ +#define LOOP_CTL_ADD 0x4C80 +#define LOOP_CTL_REMOVE 0x4C81 +#define LOOP_CTL_GET_FREE 0x4C82#endif
linux-user/syscall_defs.h +4 -0
@@ -1129,6 +1129,10 @@ struct target_pollfd {#define TARGET_LOOP_GET_STATUS64 0x4C05#define TARGET_LOOP_CHANGE_FD 0x4C06 +#define TARGET_LOOP_CTL_ADD 0x4C80 +#define TARGET_LOOP_CTL_REMOVE 0x4C81 +#define TARGET_LOOP_CTL_GET_FREE 0x4C82 +/* fb ioctls */ #define TARGET_FBIOGET_VSCREENINFO 0x4600#define TARGET_FBIOPUT_VSCREENINFO 0x4601
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 1/2] linux-user: Add loop control ioctls
Quoted 6 lines · Peter Maydell
Add support for the
/dev/loop-controlioctls:
LOOP_CTL_ADD
LOOP_CTL_REMOVE
LOOP_CTL_GET_FREESigned-off-by Peter Maydell <[email protected]>
Quoted 62 lines
--- linux-user/ioctls.h | 4 ++++ linux-user/linux_loop.h | 11 ++++++++++- linux-user/syscall_defs.h | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-)linux-user/ioctls.h +4
-0@@ -356,6 +356,10 @@ IOCTL(LOOP_GET_STATUS64, IOC_W, MK_PTR(MK_STRUCT(STRUCT_loop_info64))) IOCTL(LOOP_CHANGE_FD, 0, TYPE_INT) + IOCTL(LOOP_CTL_ADD, 0, TYPE_INT) + IOCTL(LOOP_CTL_REMOVE, 0, TYPE_INT) + IOCTL(LOOP_CTL_GET_FREE, 0, TYPE_NULL) + IOCTL(MTIOCTOP, IOC_W, MK_PTR(MK_STRUCT(STRUCT_mtop))) IOCTL(MTIOCGET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_mtget)))IOCTL (MTIOCPOS ,IOC_R ,MK_PTR (MK_STRUCT (STRUCT_mtpos)))linux-user/linux_loop.h +10
-1@@ -1,4 +1,6 @@ -/* Copied from 2.6.25 kernel headers to avoid problems on older hosts. */ +/* Copied from 2.6.25 kernel headers to avoid problems on older hosts, +* and subsequently updated to match newer additions to the API. +*/ #ifndef _LINUX_LOOP_H#define _LINUX_LOOP_H@@ -91,5 +93,12 @@ struct loop_info64 {#define LOOP_SET_STATUS64 0x4C04#define LOOP_GET_STATUS64 0x4C05#define LOOP_CHANGE_FD 0x4C06 +#define LOOP_SET_CAPACITY 0x4C07 +#define LOOP_SET_DIRECT_IO 0x4C08 + +/* /dev/loop-control interface */ +#define LOOP_CTL_ADD 0x4C80 +#define LOOP_CTL_REMOVE 0x4C81 +#define LOOP_CTL_GET_FREE 0x4C82#endif linux-user/syscall_defs.h +4
-0@@ -1129,6 +1129,10 @@ struct target_pollfd {#define TARGET_LOOP_GET_STATUS64 0x4C05#define TARGET_LOOP_CHANGE_FD 0x4C06 +#define TARGET_LOOP_CTL_ADD 0x4C80 +#define TARGET_LOOP_CTL_REMOVE 0x4C81 +#define TARGET_LOOP_CTL_GET_FREE 0x4C82 +/* fb ioctls */ #define TARGET_FBIOGET_VSCREENINFO 0x4600#define TARGET_FBIOPUT_VSCREENINFO 0x4601
PATCH 2/2 linux-user: Correct type for BLKSSZGET
In reply to Peter MaydellThe BLKSSZGET ioctl takes an argument which is a pointer to an int. We were incorrectly declaring it to take a pointer to a long, which meant that we would incorrectly write to memory which we should not if the guest is a 64-bit architecture.
In particular, kpartx uses this ioctl to write to an int on the stack, which tends to result in it crashing immediately.
--- linux-user/ioctls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/ioctls.h +1 -1
@@ -76,7 +76,7 @@ IOCTL(BLKFLSBUF, 0, TYPE_NULL) IOCTL(BLKRASET, 0, TYPE_INT) IOCTL(BLKRAGET, IOC_R, MK_PTR(TYPE_LONG)) - IOCTL(BLKSSZGET, IOC_R, MK_PTR(TYPE_LONG)) + IOCTL(BLKSSZGET, IOC_R, MK_PTR(TYPE_INT)) IOCTL(BLKBSZGET, IOC_R, MK_PTR(TYPE_INT))IOCTL_SPECIAL (BLKPG ,IOC_W , do_ioctl_blkpg,MK_PTR (MK_STRUCT (STRUCT_blkpg_ioctl_arg)))
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 2/2] linux-user: Correct type for BLKSSZGET
Quoted 10 lines · Peter Maydell
The BLKSSZGET ioctl takes an argument which is a pointer to an int. We were incorrectly declaring it to take a pointer to a long, which meant that we would incorrectly write to memory which we should not if the guest is a 64-bit architecture.
In particular, kpartx uses this ioctl to write to an int on the stack, which tends to result in it crashing immediately.
Reported-by Chanho Park <[email protected]>Signed-off-by Peter Maydell <[email protected]>
Quoted 18 lines
--- linux-user/ioctls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/ioctls.h +1
-1@@ -76,7 +76,7 @@ IOCTL(BLKFLSBUF, 0, TYPE_NULL) IOCTL(BLKRASET, 0, TYPE_INT) IOCTL(BLKRAGET, IOC_R, MK_PTR(TYPE_LONG)) - IOCTL(BLKSSZGET, IOC_R, MK_PTR(TYPE_LONG)) + IOCTL(BLKSSZGET, IOC_R, MK_PTR(TYPE_INT)) IOCTL(BLKBSZGET, IOC_R, MK_PTR(TYPE_INT))IOCTL_SPECIAL (BLKPG ,IOC_W , do_ioctl_blkpg,MK_PTR (MK_STRUCT (STRUCT_blkpg_ioctl_arg)))
Hi Peter,
Quoted 10 lines · Peter Maydell
This patchset fixes a couple of ioctl bugs which were causing problems with running kpartx:
(1) add the missing ioctls for the loop-control device
(2) fix the BLKSSZGET ioctl not to trash memory on 64-bit guestsPeter Maydell (2):
linux-user: Add loop control ioctls
linux-user: Correct type for BLKSSZGET
Quoted 9 lines
linux-user/ioctls.h | 6 +++++- linux-user/linux_loop.h | 11 ++++++++++- linux-user/syscall_defs.h | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-)--
1.9.1
I've verified it's fixed and kpartx is working well.
Signature · 2 lines
Best Regards, Chanho Park