* [PATCH] e2fslibs: fix llseek on i386
@ 2013-01-24 16:21 Phillip Susi
2013-01-24 19:51 ` Theodore Ts'o
2013-01-25 4:13 ` Theodore Ts'o
0 siblings, 2 replies; 10+ messages in thread
From: Phillip Susi @ 2013-01-24 16:21 UTC (permalink / raw)
To: tytso; +Cc: linux-ext4, Phillip Susi
ext2fs_llseek() was using lseek instead of lseek64. The
only time it would use lseek64 is if passed an offset that
overflowed 32 bits. This works for SEEK_SET, but not
SEEK_CUR, which can apply a small offset to move the file
pointer past the 32 bit limit.
The code has been changed to instead try lseek64 first, and
fall back to lseek if that fails. It also was doing a
runtime check of the size of off_t. This has been moved to
compile time.
Signed-off-by: Phillip Susi <psusi@ubuntu.com>
---
configure.in | 3 +++
lib/config.h.in | 3 +++
lib/ext2fs/llseek.c | 13 +++++--------
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/configure.in b/configure.in
index ac3cd92..181faeb 100644
--- a/configure.in
+++ b/configure.in
@@ -970,14 +970,17 @@ AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
+AC_CHECK_SIZEOF(off_t)
SIZEOF_SHORT=$ac_cv_sizeof_short
SIZEOF_INT=$ac_cv_sizeof_int
SIZEOF_LONG=$ac_cv_sizeof_long
SIZEOF_LONG_LONG=$ac_cv_sizeof_long_long
+SIZEOF_OFF_T=$ac_cv_sizeof_off_t
AC_SUBST(SIZEOF_SHORT)
AC_SUBST(SIZEOF_INT)
AC_SUBST(SIZEOF_LONG)
AC_SUBST(SIZEOF_LONG_LONG)
+AC_SUBST(SIZEOF_OFF_T)
AC_C_BIGENDIAN
BUILD_CC="$BUILD_CC" CPP="$CPP" /bin/sh $ac_aux_dir/parse-types.sh
ASM_TYPES_HEADER=./asm_types.h
diff --git a/lib/config.h.in b/lib/config.h.in
index 6f88c9c..eebb75d 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -552,6 +552,9 @@
/* The size of `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
+/* The size of `off_t', as computed by sizeof. */
+#undef SIZEOF_OFF_T
+
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c
index b0576e4..e5cb784 100644
--- a/lib/ext2fs/llseek.c
+++ b/lib/ext2fs/llseek.c
@@ -90,18 +90,14 @@ static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
{
+#if SIZEOF_OFF_T >= SIZEOF_LONG_LONG
+ return lseek (fd, offset, origin);
+#else
ext2_loff_t result;
static int do_compat = 0;
- if ((sizeof(off_t) >= sizeof(ext2_loff_t)) ||
- (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))))
+ if (do_compat)
return lseek(fd, (off_t) offset, origin);
-
- if (do_compat) {
- errno = EINVAL;
- return -1;
- }
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-24 16:21 [PATCH] e2fslibs: fix llseek on i386 Phillip Susi
@ 2013-01-24 19:51 ` Theodore Ts'o
2013-01-24 20:22 ` Phillip Susi
2013-01-25 4:13 ` Theodore Ts'o
1 sibling, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2013-01-24 19:51 UTC (permalink / raw)
To: Phillip Susi; +Cc: linux-ext4
On Thu, Jan 24, 2013 at 11:21:56AM -0500, Phillip Susi wrote:
> ext2fs_llseek() was using lseek instead of lseek64. The
> only time it would use lseek64 is if passed an offset that
> overflowed 32 bits. This works for SEEK_SET, but not
> SEEK_CUR, which can apply a small offset to move the file
> pointer past the 32 bit limit.
>
> The code has been changed to instead try lseek64 first, and
> fall back to lseek if that fails. It also was doing a
> runtime check of the size of off_t. This has been moved to
> compile time.
>
> Signed-off-by: Phillip Susi <psusi@ubuntu.com>
How did you find this? I've done a quick search for SEEK_CUR, and it
looks like only place where this could cause a problem is with
e2image. And a quick test of a i386 version of e2image with a large
file system is that it does indeed blow up with an "Inappropriate
ioctl for device" error.
Is there any other potential problems that are caused by this bug? I
like to explain the impacts of bug fixes in libext2fs for folks who
are doing bug fix / code archeology.
Thanks,
- Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-24 19:51 ` Theodore Ts'o
@ 2013-01-24 20:22 ` Phillip Susi
2013-01-24 20:32 ` Theodore Ts'o
0 siblings, 1 reply; 10+ messages in thread
From: Phillip Susi @ 2013-01-24 20:22 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: linux-ext4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 1/24/2013 2:51 PM, Theodore Ts'o wrote:
> How did you find this? I've done a quick search for SEEK_CUR, and
> it looks like only place where this could cause a problem is with
> e2image. And a quick test of a i386 version of e2image with a
> large file system is that it does indeed blow up with an
> "Inappropriate ioctl for device" error.
That's where I found it, but the error should be "seek: Value too
large for defined data type"
> Is there any other potential problems that are caused by this bug?
> I like to explain the impacts of bug fixes in libext2fs for folks
> who are doing bug fix / code archeology.
If e2image is the only internal user of the call with SEEK_CUR, then I
guess it only affects any external users of the library who were doing
this ( I am not aware of any ).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJRAZgNAAoJEJrBOlT6nu752g0IAN4czK0LevEa9Mx2htaZ3oms
TtcpKe7tuXgmvLB0XWv8Q2f6zCDMH7qmWqWZORdx98jg2XeynaEbZvVIQFEsfOVa
05r7sk64TPGXrdkwuqFTe4M7MYmrQmLnfGzd2NMddlWcXOc+R4pFUrrvYbU7QQv/
SGfb9Uo+EFZhSuJLPY1QW4EO09ghD4k6XHnHtioAsgjyxSa4p2NcZiBxmFT7ZJdw
DbET65wHkKT2s+jLQQAOPx/IYAftrZuV7t+YoX7RTS4tdpENlgoVlZ3drCvHB2aG
LwDDns4C1e0cAMncGKh3HY4/CInMZ1jFWHYW+VvuzZNJ7Uxur2mG6NUyWp6cNqU=
=WeEv
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-24 20:22 ` Phillip Susi
@ 2013-01-24 20:32 ` Theodore Ts'o
2013-01-25 2:25 ` Zheng Liu
0 siblings, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2013-01-24 20:32 UTC (permalink / raw)
To: Phillip Susi; +Cc: linux-ext4
On Thu, Jan 24, 2013 at 03:22:37PM -0500, Phillip Susi wrote:
>
> On 1/24/2013 2:51 PM, Theodore Ts'o wrote:
> > How did you find this? I've done a quick search for SEEK_CUR, and
> > it looks like only place where this could cause a problem is with
> > e2image. And a quick test of a i386 version of e2image with a
> > large file system is that it does indeed blow up with an
> > "Inappropriate ioctl for device" error.
>
> That's where I found it, but the error should be "seek: Value too
> large for defined data type"
Well, I did my testing using an i386 debian/testing chroot running
under a x86-64 3.8.0-rc3 kernel. I'm guessing it was the use of a
32-bit userspace / 64-bit kernel that probably explains the
difference.
> > Is there any other potential problems that are caused by this bug?
> > I like to explain the impacts of bug fixes in libext2fs for folks
> > who are doing bug fix / code archeology.
>
> If e2image is the only internal user of the call with SEEK_CUR, then I
> guess it only affects any external users of the library who were doing
> this ( I am not aware of any ).
Well, there are some binaries that aren't usually built by most
distributions (make-sparse and copy-sparse), but in terms of primary
e2fsprogs programs (mke2fs, e2fskc, tune2fs, chattr, lsattr, etc.)
nope, none of them use SEEK_CUR.
The lib/ext2fs/fileio.c file does use SEEK_CUR, which means it might
impact 3rd party packages such as e2tools and ext2fuse (although
that's generally only used on Mac and Windows systems).
Cheers,
- Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-24 20:32 ` Theodore Ts'o
@ 2013-01-25 2:25 ` Zheng Liu
2013-01-25 2:16 ` Theodore Ts'o
0 siblings, 1 reply; 10+ messages in thread
From: Zheng Liu @ 2013-01-25 2:25 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Phillip Susi, linux-ext4
On Thu, Jan 24, 2013 at 03:32:30PM -0500, Theodore Ts'o wrote:
> On Thu, Jan 24, 2013 at 03:22:37PM -0500, Phillip Susi wrote:
> >
> > On 1/24/2013 2:51 PM, Theodore Ts'o wrote:
> > > How did you find this? I've done a quick search for SEEK_CUR, and
> > > it looks like only place where this could cause a problem is with
> > > e2image. And a quick test of a i386 version of e2image with a
> > > large file system is that it does indeed blow up with an
> > > "Inappropriate ioctl for device" error.
> >
> > That's where I found it, but the error should be "seek: Value too
> > large for defined data type"
>
> Well, I did my testing using an i386 debian/testing chroot running
> under a x86-64 3.8.0-rc3 kernel. I'm guessing it was the use of a
> 32-bit userspace / 64-bit kernel that probably explains the
> difference.
>
> > > Is there any other potential problems that are caused by this bug?
> > > I like to explain the impacts of bug fixes in libext2fs for folks
> > > who are doing bug fix / code archeology.
> >
> > If e2image is the only internal user of the call with SEEK_CUR, then I
> > guess it only affects any external users of the library who were doing
> > this ( I am not aware of any ).
>
> Well, there are some binaries that aren't usually built by most
> distributions (make-sparse and copy-sparse), but in terms of primary
> e2fsprogs programs (mke2fs, e2fskc, tune2fs, chattr, lsattr, etc.)
> nope, none of them use SEEK_CUR.
>
> The lib/ext2fs/fileio.c file does use SEEK_CUR, which means it might
> impact 3rd party packages such as e2tools and ext2fuse (although
> that's generally only used on Mac and Windows systems).
Hi Ted,
This patch makes me consider my patches that dump a sparse file in
debugfs. In my patch [1] llseek64(2) is called to seek to the next
data in target file. So I believe ext2fs_llseek() is a better choice.
I am happy to send a newer patch to fix it. What do you think?
1. http://www.spinics.net/lists/linux-ext4/msg36134.html
Thanks,
- Zheng
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-25 2:25 ` Zheng Liu
@ 2013-01-25 2:16 ` Theodore Ts'o
2013-01-25 2:48 ` Zheng Liu
0 siblings, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2013-01-25 2:16 UTC (permalink / raw)
To: Phillip Susi, linux-ext4
On Fri, Jan 25, 2013 at 10:25:14AM +0800, Zheng Liu wrote:
>
> This patch makes me consider my patches that dump a sparse file in
> debugfs. In my patch [1] llseek64(2) is called to seek to the next
> data in target file. So I believe ext2fs_llseek() is a better choice.
> I am happy to send a newer patch to fix it. What do you think?
>
> 1. http://www.spinics.net/lists/linux-ext4/msg36134.html
You're right, we should use ext2fs_llseek() for better portability.
Thanks,
- Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-25 2:16 ` Theodore Ts'o
@ 2013-01-25 2:48 ` Zheng Liu
0 siblings, 0 replies; 10+ messages in thread
From: Zheng Liu @ 2013-01-25 2:48 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Phillip Susi, linux-ext4
On Thu, Jan 24, 2013 at 09:16:05PM -0500, Theodore Ts'o wrote:
> On Fri, Jan 25, 2013 at 10:25:14AM +0800, Zheng Liu wrote:
> >
> > This patch makes me consider my patches that dump a sparse file in
> > debugfs. In my patch [1] llseek64(2) is called to seek to the next
> > data in target file. So I believe ext2fs_llseek() is a better choice.
> > I am happy to send a newer patch to fix it. What do you think?
> >
> > 1. http://www.spinics.net/lists/linux-ext4/msg36134.html
>
> You're right, we should use ext2fs_llseek() for better portability.
> Thanks,
Yep, the next version will be sent out soon.
Regards,
- Zheng
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] e2fslibs: fix llseek on i386
2013-01-24 16:21 [PATCH] e2fslibs: fix llseek on i386 Phillip Susi
2013-01-24 19:51 ` Theodore Ts'o
@ 2013-01-25 4:13 ` Theodore Ts'o
2013-01-25 4:14 ` [PATCH] libext2fs: fix ext2fs_llseek " Theodore Ts'o
1 sibling, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2013-01-25 4:13 UTC (permalink / raw)
To: Phillip Susi; +Cc: linux-ext4
On Thu, Jan 24, 2013 at 11:21:56AM -0500, Phillip Susi wrote:
> ext2fs_llseek() was using lseek instead of lseek64. The
> only time it would use lseek64 is if passed an offset that
> overflowed 32 bits. This works for SEEK_SET, but not
> SEEK_CUR, which can apply a small offset to move the file
> pointer past the 32 bit limit.
>
> The code has been changed to instead try lseek64 first, and
> fall back to lseek if that fails. It also was doing a
> runtime check of the size of off_t. This has been moved to
> compile time.
>
> Signed-off-by: Phillip Susi <psusi@ubuntu.com>
Applied, although I had to make a small change so that in the case
where llseek doesn't exist, we need to retry with lseek immediately.
Also, in the fallback case, we still need to make the runtime check to
assure that the requested offset is less than off_t.
On the 1.43 branch it probably makes sense to get rid of the whole
mess with my_llseek and just use llseek64 directly. There's a bunch
of complexity here which because over a decade ago, glibc had a buggy
header files which caused llseek64 to malfunction (which is why I
didn't enable use of llseek64 and > 2GB file system support in the
first place), and the Debian developer at the time tried to be too
clever and shipped a patched version of e2fsprogs which tried to use
llseek64 without consulting me first, and then users started losing
data and having the file systems corrupted as a result.
So as a result, because I couldn't trust glibc to give me a non-buggy
version of llseek64, and Debian users were losing data in real time, I
had e2fsprogs call the system call directly. It's been a long time
since systems with this particular glibc Fail have been around, so
eventually I should rip out a lot of this mess.
- Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] libext2fs: fix ext2fs_llseek on i386
2013-01-25 4:13 ` Theodore Ts'o
@ 2013-01-25 4:14 ` Theodore Ts'o
2013-01-25 4:34 ` Phillip Susi
0 siblings, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2013-01-25 4:14 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: psusi, Theodore Ts'o
From: Phillip Susi <psusi@ubuntu.com>
ext2fs_llseek() was using lseek instead of lseek64. The
only time it would use lseek64 is if passed an offset that
overflowed 32 bits. This works for SEEK_SET, but not
SEEK_CUR, which can apply a small offset to move the file
pointer past the 32 bit limit.
The code has been changed to instead try lseek64 first, and
fall back to lseek if that fails. It also was doing a
runtime check of the size of off_t. This has been moved to
compile time.
This fixes a problem which would cause e2image when built for
x86-32 to bomb out when used with large file systems.
Signed-off-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
configure.in | 3 +++
lib/config.h.in | 3 +++
lib/ext2fs/llseek.c | 18 ++++++++++--------
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/configure.in b/configure.in
index cf96e43..c3687bb 100644
--- a/configure.in
+++ b/configure.in
@@ -916,14 +916,17 @@ AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
+AC_CHECK_SIZEOF(off_t)
SIZEOF_SHORT=$ac_cv_sizeof_short
SIZEOF_INT=$ac_cv_sizeof_int
SIZEOF_LONG=$ac_cv_sizeof_long
SIZEOF_LONG_LONG=$ac_cv_sizeof_long_long
+SIZEOF_OFF_T=$ac_cv_sizeof_off_t
AC_SUBST(SIZEOF_SHORT)
AC_SUBST(SIZEOF_INT)
AC_SUBST(SIZEOF_LONG)
AC_SUBST(SIZEOF_LONG_LONG)
+AC_SUBST(SIZEOF_OFF_T)
AC_C_BIGENDIAN
BUILD_CC="$BUILD_CC" CPP="$CPP" /bin/sh $ac_aux_dir/parse-types.sh
ASM_TYPES_HEADER=./asm_types.h
diff --git a/lib/config.h.in b/lib/config.h.in
index 90e9743..e14eff4 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -543,6 +543,9 @@
/* The size of `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
+/* The size of `off_t', as computed by sizeof. */
+#undef SIZEOF_OFF_T
+
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c
index b0576e4..c3a98a2 100644
--- a/lib/ext2fs/llseek.c
+++ b/lib/ext2fs/llseek.c
@@ -90,17 +90,14 @@ static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
{
+#if SIZEOF_OFF_T >= SIZEOF_LONG_LONG
+ return lseek (fd, offset, origin);
+#else
ext2_loff_t result;
static int do_compat = 0;
- if ((sizeof(off_t) >= sizeof(ext2_loff_t)) ||
- (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))))
- return lseek(fd, (off_t) offset, origin);
-
- if (do_compat) {
- errno = EINVAL;
- return -1;
- }
+ if (do_compat)
+ goto fallback;
result = my_llseek (fd, offset, origin);
if (result == -1 && errno == ENOSYS) {
@@ -109,9 +106,14 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
* which does not support the llseek system call
*/
do_compat++;
+ fallback:
+ if (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))
+ return lseek(fd, (off_t) offset, origin);
errno = EINVAL;
+ return -1;
}
return result;
+#endif
}
#else /* !linux */
--
1.7.12.rc0.22.gcdd159b
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] libext2fs: fix ext2fs_llseek on i386
2013-01-25 4:14 ` [PATCH] libext2fs: fix ext2fs_llseek " Theodore Ts'o
@ 2013-01-25 4:34 ` Phillip Susi
0 siblings, 0 replies; 10+ messages in thread
From: Phillip Susi @ 2013-01-25 4:34 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 01/24/2013 11:14 PM, Theodore Ts'o wrote:
> + fallback: + if (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8)
> -1))) + return lseek(fd, (off_t) offset, origin); errno =
> EINVAL;
Shouldn't that be EOVERFLOW?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/
iQEcBAEBAgAGBQJRAgtjAAoJEJrBOlT6nu75II4H/07hJXsFEGxetEpJGdshSxBc
YTixcONEBDlzppAtLr/aLmHDGr+0269Wjrdj0EhrEqIqlkMG3sRcEkkBoGE7bXbm
3oYLru+YtdVFuDfvZ6PDuConYD/Ud711uLP1Bu2gJN0fGO0l+cg0v1VIirKgaDMO
pB468llpVxMY3Tj9SN5JB7Np0ZS3qxhMpYc3RGsObRamU/BHcIRYw65K8Vsgi4xa
jtf6O8/bQm2AUB+d4IRBuR+KV0/HWFCYtcfSBh/iv/e3aWr2CXA59J5WuGpCfWAM
a72+S9Ek7IOiTi2H59swh2bCSajf01da1JvA26f6yBH7KrY2mvWys1/C/3liUzs=
=/V1N
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-01-25 4:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-24 16:21 [PATCH] e2fslibs: fix llseek on i386 Phillip Susi
2013-01-24 19:51 ` Theodore Ts'o
2013-01-24 20:22 ` Phillip Susi
2013-01-24 20:32 ` Theodore Ts'o
2013-01-25 2:25 ` Zheng Liu
2013-01-25 2:16 ` Theodore Ts'o
2013-01-25 2:48 ` Zheng Liu
2013-01-25 4:13 ` Theodore Ts'o
2013-01-25 4:14 ` [PATCH] libext2fs: fix ext2fs_llseek " Theodore Ts'o
2013-01-25 4:34 ` Phillip Susi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).