From: Paul Floyd Date: Sun, 5 Mar 2023 07:38:34 +0000 (+0100) Subject: Bug 449309 - Missing loopback device ioctl(s) X-Git-Tag: VALGRIND_3_21_0~150 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=cb7adf4a9eaa06951afd8a066df3da6fcc095e5b;p=valgrind.git Bug 449309 - Missing loopback device ioctl(s) Patch provided by: Faheem Sheikh Note that the testcase provided with this report hasn't been added as it requires privileges. --- diff --git a/NEWS b/NEWS index e31fc3c50d..61c4e03053 100644 --- a/NEWS +++ b/NEWS @@ -89,6 +89,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 444568 drd/tests/pth_barrier_thr_cr fails on Fedora 38 445743 "The impossible happened: mutex is locked simultaneously by two threads" while using mutexes with priority inheritance and signals +449309 Missing loopback device ioctl(s) 459476 vgdb: allow address reuse to avoid "address already in use" errorsuse" errors 460356 s390: Sqrt32Fx4 -- cannot reduce tree 462830 WARNING: unhandled amd64-freebsd syscall: 474 diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 4a5a93b35a..34d4cf1f55 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -7861,6 +7861,32 @@ PRE(sys_ioctl) PRE_MEM_WRITE( "ioctl(RTC_IRQP_READ)", ARG3, sizeof(unsigned long)); break; + /* Loopback control */ + case VKI_LOOP_CTL_ADD: + case VKI_LOOP_CTL_REMOVE: + case VKI_LOOP_CTL_GET_FREE: + break; + /* Loopback device */ + case VKI_LOOP_SET_FD: + case VKI_LOOP_CLR_FD: + case VKI_LOOP_CHANGE_FD: + case VKI_LOOP_SET_CAPACITY: + case VKI_LOOP_SET_DIRECT_IO: + case VKI_LOOP_SET_BLOCK_SIZE: + break; + case VKI_LOOP_SET_STATUS: + PRE_MEM_READ("ioctl(LOOP_SET_STATUS)", ARG3, sizeof(struct vki_loop_info)); + break; + case VKI_LOOP_GET_STATUS: + PRE_MEM_WRITE("ioctl(LOOP_GET_STATUS)", ARG3, sizeof(struct vki_loop_info)); + break; + case VKI_LOOP_SET_STATUS64: + PRE_MEM_READ("ioctl(LOOP_SET_STATUS64)", ARG3, sizeof(struct vki_loop_info64)); + break; + case VKI_LOOP_GET_STATUS64: + PRE_MEM_WRITE("ioctl(LOOP_GET_STATUS64)", ARG3, sizeof(struct vki_loop_info64)); + break; + /* Block devices */ case VKI_BLKROSET: PRE_MEM_READ( "ioctl(BLKROSET)", ARG3, sizeof(int)); @@ -10828,6 +10854,33 @@ POST(sys_ioctl) POST_MEM_WRITE(ARG3, sizeof(unsigned long)); break; + /* Loopback devices */ + case VKI_LOOP_CTL_ADD: + case VKI_LOOP_CTL_REMOVE: + case VKI_LOOP_CTL_GET_FREE: + break; + /* Loopback device */ + case VKI_LOOP_SET_FD: + case VKI_LOOP_CLR_FD: + case VKI_LOOP_CHANGE_FD: + case VKI_LOOP_SET_CAPACITY: + case VKI_LOOP_SET_DIRECT_IO: + case VKI_LOOP_SET_BLOCK_SIZE: + break; + case VKI_LOOP_SET_STATUS: + POST_MEM_WRITE(ARG3, sizeof(struct vki_loop_info)); + break; + case VKI_LOOP_GET_STATUS: + POST_MEM_WRITE(ARG3, sizeof(struct vki_loop_info)); + break; + case VKI_LOOP_SET_STATUS64: + POST_MEM_WRITE(ARG3, sizeof(struct vki_loop_info64)); + break; + case VKI_LOOP_GET_STATUS64: + POST_MEM_WRITE(ARG3, sizeof(struct vki_loop_info64)); + break; + + /* Block devices */ case VKI_BLKROSET: break; diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index c963837015..be3d76690c 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -1872,6 +1872,62 @@ struct vki_ppdev_frob_struct { #define VKI_PPGETFLAGS _VKI_IOR(VKI_PP_IOCTL, 0x9a, int) #define VKI_PPSETFLAGS _VKI_IOW(VKI_PP_IOCTL, 0x9b, int) +//---------------------------------------------------------------------- +// From linux-5.2.5/include/uapi/linux/loop.h +//---------------------------------------------------------------------- + +#define VKI_LO_NAME_SIZE 64 +#define VKI_LO_KEY_SIZE 32 + +struct vki_loop_info { + + int lo_number; /* ioctl r/o */ + unsigned short lo_device; /* ioctl r/o */ + unsigned long lo_inode; /* ioctl r/o */ + unsigned short lo_rdevice; /* ioctl r/o */ + int lo_offset; + int lo_encrypt_type; + int lo_encrypt_key_size; /* ioctl w/o */ + int lo_flags; /* ioctl r/o */ + char lo_name[VKI_LO_NAME_SIZE]; + unsigned char lo_encrypt_key[VKI_LO_KEY_SIZE];/* ioctl w/o */ + unsigned long lo_init[2]; + char reserved[4]; +}; + +struct vki_loop_info64 { + __vki_u64 lo_device; /* ioctl r/o */ + __vki_u64 lo_inode; /* ioctl r/o */ + __vki_u64 lo_rdevice; /* ioctl r/o */ + __vki_u64 lo_offset; + __vki_u64 lo_sizelimit;/* bytes, 0 == max available */ + __vki_u32 lo_number; /* ioctl r/o */ + __vki_u32 lo_encrypt_type; + __vki_u32 lo_encrypt_key_size; /* ioctl w/o */ + __vki_u32 lo_flags; /* ioctl r/o */ + __vki_u8 lo_file_name[VKI_LO_NAME_SIZE]; + __vki_u8 lo_crypt_name[VKI_LO_NAME_SIZE]; + __vki_u8 lo_encrypt_key[VKI_LO_KEY_SIZE]; /* ioctl w/o */ + __vki_u64 lo_init[2]; +}; + +/* loopback device related, e.g. see losetup program options */ +#define VKI_LOOP_SET_FD 0x4C00 +#define VKI_LOOP_CLR_FD 0x4C01 +#define VKI_LOOP_SET_STATUS 0x4C02 +#define VKI_LOOP_GET_STATUS 0x4C03 +#define VKI_LOOP_SET_STATUS64 0x4C04 +#define VKI_LOOP_GET_STATUS64 0x4C05 +#define VKI_LOOP_CHANGE_FD 0x4C06 +#define VKI_LOOP_SET_CAPACITY 0x4C07 +#define VKI_LOOP_SET_DIRECT_IO 0x4C08 +#define VKI_LOOP_SET_BLOCK_SIZE 0x4C09 + +/* ioctls for loop-control device interface */ +#define VKI_LOOP_CTL_ADD 0x4C80 // adds a new loopback device +#define VKI_LOOP_CTL_REMOVE 0x4C81 // deletes an existing loopback device +#define VKI_LOOP_CTL_GET_FREE 0x4C82 // finds a free/available loopback device + //---------------------------------------------------------------------- // From linux-5.2.5/include/uapi/linux/fs.h //----------------------------------------------------------------------