From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/fcntl34: use struct flock64 on 32bit
Date: Mon, 13 Jun 2016 16:22:10 +0200 [thread overview]
Message-ID: <20160613142210.GA354@rei.lan> (raw)
In-Reply-To: <1465562609-11947-1-git-send-email-jjaburek@redhat.com>
Hi!
> On x86, compiled as 32bit:
>
> fcntl34.c:113: INFO: write to a file inside threads with OFD locks
> fcntl34.c:47: INFO: spawning '3' threads
> fcntl34.c:56: INFO: waiting for '3' threads
> fcntl34.c:88: BROK: fcntl() failed: EINVAL
>
> This is because glibc translates fcntl() to sys_fcntl64,
>
> [pid 19656] fcntl64(4, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET,
> l_start=4294967296, l_len=-695062700769673216}) = -1 EINVAL
> (Invalid argument)
>
> as advised by the kernel,
>
> /* 32-bit arches must use fcntl64() */
> case F_OFD_SETLK:
> case F_OFD_SETLKW:
>
> but the struct passed uses 32bit values,
>
> struct flock lck = {
> .l_whence = SEEK_SET,
> .l_start = 0,
> .l_len = 1,
> };
>
> which are read as 64bit by the kernel,
>
> int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
> struct flock64 __user *l)
>
> causing the garbage in upper 32bit of at least l_start and l_len to be
> treated as offsets, resulting in EINVAL.
>
> This patch makes the test use struct flock64 when _FILE_OFFSET_BITS
> is unset.
Since both manual and glibc examples use struct flock with OFD locks in
examples and if I compile glibc example for OFD locks[1] on 32bit system
garbage is passed to kernel syscalls and the program hangs, so I would
call this glibc/kernel bug.
I would expect glibc to convert the flock structure to 64 bit one
silently in this case.
[1] manual/examples/ofdlocks.c
https://sourceware.org/git/?p=glibc.git;a=blob;f=manual/examples/ofdlocks.c;h=ba4f0ef4d237e95b8f1e0f37b9c1befd4afda0d4;hb=HEAD
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2016-06-13 14:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 12:43 [LTP] [PATCH] syscalls/fcntl34: use struct flock64 on 32bit Jiri Jaburek
2016-06-10 14:04 ` Jiri Jaburek
2016-06-10 14:50 ` [LTP] [PATCH v2] syscalls/fcntl34: disable on 32bit without _FILE_OFFSET_BITS==64 Jiri Jaburek
2016-06-13 14:22 ` Cyril Hrubis [this message]
2016-06-13 17:58 ` [LTP] [PATCH] syscalls/fcntl34: use struct flock64 on 32bit Jiri Jaburek
2016-06-13 18:25 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160613142210.GA354@rei.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox