Skip to contentSkip to conversation

linux-user: fix kpartx ioctl problems

PATCH In review Peter Maydell 3 participants 6 messages Jul 4, 2016 – Jul 5, 2016

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 804f099..72cd32a 100644
@@ -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
index 8974caa..fd7608b 100644
@@ -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
index 6650e26..0591abc 100644
@@ -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
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] linux-user: Add loop control ioctls

Quoted 6 lines · Peter Maydell

Add support for the /dev/loop-control ioctls:
LOOP_CTL_ADD
LOOP_CTL_REMOVE
LOOP_CTL_GET_FREE

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
index 804f099..72cd32a 100644
@@ -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
index 8974caa..fd7608b 100644
@@ -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
index 6650e26..0591abc 100644
@@ -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
#3 lore raw

PATCH 2/2 linux-user: Correct type for BLKSSZGET

In reply to 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.

---
 linux-user/ioctls.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/ioctls.h +1 -1
index 72cd32a..8978eb3 100644
@@ -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
Reviewed-by on v1 2/2
#4 lore raw

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.

Quoted 18 lines
---
 linux-user/ioctls.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/ioctls.h +1 -1
index 72cd32a..8978eb3 100644
@@ -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)))
Tested-by on the v1 series
#5 lore raw
In reply to Peter Maydell

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 guests

Peter 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