Otherwise, stack can be corrupted resulting in incorrect runtime behaviour. For example, overriding argc from main(). References: https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/1850184 Signed-off-by: Michael Hudson-Doyle <michael.hudson at ubuntu.com> Signed-off-by: Adam Conrad <adconrad at ubuntu.com> Signed-off-by: Dimitri John Ledkov <xnox at ubuntu.com> --- usr/utils/loop.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/utils/loop.h b/usr/utils/loop.h index 9abc2874..667f7dc0 100644 --- a/usr/utils/loop.h +++ b/usr/utils/loop.h @@ -15,9 +15,9 @@ struct loop_info { int lo_number; - dev_t lo_device; + __kernel_old_dev_t lo_device; unsigned long lo_inode; - dev_t lo_rdevice; + __kernel_old_dev_t lo_rdevice; int lo_offset; int lo_encrypt_type; int lo_encrypt_key_size; -- 2.20.1
Dimitri John Ledkov
2019-Oct-31 22:59 UTC
[klibc] [PATCH 2/2] loop: switch to linux/loop.h
linux/loop.h header is exported by linux, for userspace to consume. This would prevent issues with struct sizes incompatibilities. References: https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/1850184 Signed-off-by: Michael Hudson-Doyle <michael.hudson at ubuntu.com> Signed-off-by: Adam Conrad <adconrad at ubuntu.com> Signed-off-by: Dimitri John Ledkov <xnox at ubuntu.com> --- usr/utils/loop.h | 49 --------------------------------------------- usr/utils/losetup.c | 3 +-- 2 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 usr/utils/loop.h diff --git a/usr/utils/loop.h b/usr/utils/loop.h deleted file mode 100644 index 667f7dc0..00000000 --- a/usr/utils/loop.h +++ /dev/null @@ -1,49 +0,0 @@ -#define LO_CRYPT_NONE 0 -#define LO_CRYPT_XOR 1 -#define LO_CRYPT_DES 2 -#define LO_CRYPT_CRYPTOAPI 18 - -#define LOOP_SET_FD 0x4C00 -#define LOOP_CLR_FD 0x4C01 -#define LOOP_SET_STATUS 0x4C02 -#define LOOP_GET_STATUS 0x4C03 -#define LOOP_SET_STATUS64 0x4C04 -#define LOOP_GET_STATUS64 0x4C05 - -#define LO_NAME_SIZE 64 -#define LO_KEY_SIZE 32 - -struct loop_info { - int lo_number; - __kernel_old_dev_t lo_device; - unsigned long lo_inode; - __kernel_old_dev_t lo_rdevice; - int lo_offset; - int lo_encrypt_type; - int lo_encrypt_key_size; - int lo_flags; - char lo_name[LO_NAME_SIZE]; - unsigned char lo_encrypt_key[LO_KEY_SIZE]; - unsigned long lo_init[2]; - char reserved[4]; -}; - -/* - * Where to get __u8, __u32, __u64? Let us use unsigned char/int/long long - * and get punished when someone comes with 128-bit long longs. - */ -struct loop_info64 { - unsigned long long lo_device; - unsigned long long lo_inode; - unsigned long long lo_rdevice; - unsigned long long lo_offset; - unsigned long long lo_sizelimit; /* bytes, 0 == max available */ - unsigned int lo_number; - unsigned int lo_encrypt_type; - unsigned int lo_encrypt_key_size; - unsigned int lo_flags; - char lo_file_name[LO_NAME_SIZE]; - char lo_crypt_name[LO_NAME_SIZE]; - char lo_encrypt_key[LO_KEY_SIZE]; - unsigned long long lo_init[2]; -}; diff --git a/usr/utils/losetup.c b/usr/utils/losetup.c index 17887412..ebc6f360 100644 --- a/usr/utils/losetup.c +++ b/usr/utils/losetup.c @@ -18,8 +18,7 @@ #include <sys/mman.h> #include <sys/sysmacros.h> #include <stdarg.h> - -#include "loop.h" +#include <linux/loop.h> extern int verbose; extern char *progname; -- 2.20.1
On Thu, 2019-10-31 at 22:59 +0000, Dimitri John Ledkov wrote:> Otherwise, stack can be corrupted resulting in incorrect runtime > behaviour. For example, overriding argc from main().The structure definition doesn't match the kernel's definition (on most architectures) which leads to undefined behaviour. The commit message should say something like that rather than specifying some particular behaviour that was observed. Ben.> References: https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/1850184 > Signed-off-by: Michael Hudson-Doyle <michael.hudson at ubuntu.com> > Signed-off-by: Adam Conrad <adconrad at ubuntu.com> > Signed-off-by: Dimitri John Ledkov <xnox at ubuntu.com> > --- > usr/utils/loop.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/usr/utils/loop.h b/usr/utils/loop.h > index 9abc2874..667f7dc0 100644 > --- a/usr/utils/loop.h > +++ b/usr/utils/loop.h > @@ -15,9 +15,9 @@ > > struct loop_info { > int lo_number; > - dev_t lo_device; > + __kernel_old_dev_t lo_device; > unsigned long lo_inode; > - dev_t lo_rdevice; > + __kernel_old_dev_t lo_rdevice; > int lo_offset; > int lo_encrypt_type; > int lo_encrypt_key_size;-- Ben Hutchings Reality is just a crutch for people who can't handle science fiction. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: <https://lists.zytor.com/archives/klibc/attachments/20191101/c0ff498d/attachment.sig>
On Thu, 2019-10-31 at 22:59 +0000, Dimitri John Ledkov wrote:> linux/loop.h header is exported by linux, for userspace to > consume. This would prevent issues with struct sizes > incompatibilities.[...] The structure definitions can't change in future, so I don't think that's a real issue after the previous patch. But I agree that we should prefer using the kernel's UAPI headers wherever possible. Ben. -- Ben Hutchings Reality is just a crutch for people who can't handle science fiction. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: <https://lists.zytor.com/archives/klibc/attachments/20191101/da98e5bb/attachment.sig>