All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Jaburek <jjaburek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/fcntl34: use struct flock64 on 32bit
Date: Fri, 10 Jun 2016 14:43:29 +0200	[thread overview]
Message-ID: <1465562609-11947-1-git-send-email-jjaburek@redhat.com> (raw)

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.

Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
---
 testcases/kernel/syscalls/fcntl/fcntl34.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/fcntl/fcntl34.c b/testcases/kernel/syscalls/fcntl/fcntl34.c
index c72951e..9c9310e 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl34.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl34.c
@@ -58,6 +58,13 @@ static void wait_threads(pthread_t *id)
 		SAFE_PTHREAD_JOIN(id[i], NULL);
 }
 
+/* F_OFD_SETLKW needs proper 64bit offsets on 32bit systems */
+#if _FILE_OFFSET_BITS == 64
+typedef struct flock flock_t;
+#else
+typedef struct flock64 flock_t;
+#endif
+
 void *thread_fn_01(void *arg)
 {
 	int i;
@@ -66,7 +73,7 @@ void *thread_fn_01(void *arg)
 
 	memset(buf, (intptr_t)arg, write_size);
 
-	struct flock lck = {
+	flock_t lck = {
 		.l_whence = SEEK_SET,
 		.l_start  = 0,
 		.l_len    = 1,
-- 
2.4.3


             reply	other threads:[~2016-06-10 12:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-10 12:43 Jiri Jaburek [this message]
2016-06-10 14:04 ` [LTP] [PATCH] syscalls/fcntl34: use struct flock64 on 32bit 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 ` [LTP] [PATCH] syscalls/fcntl34: use struct flock64 on 32bit Cyril Hrubis
2016-06-13 17:58   ` 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=1465562609-11947-1-git-send-email-jjaburek@redhat.com \
    --to=jjaburek@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.