public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: John Engel <jhe@us.ibm.com>
To: akpm@osdl.org
Cc: willy@debian.org, sfr@au1.ibm.com, linux-kernel@vger.kernel.org
Subject: [PATCH] compat_sys_fcntl64: fix for locking near end of file
Date: Thu, 16 Sep 2004 14:58:48 -0500	[thread overview]
Message-ID: <4149F078.7080006@us.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 625 bytes --]

Andrew,
     Here's a patch to fix a bug in compat_sys_fcntl64 in fs/compat.c.
The bug occurs with a 32 bit app that calls fcntl and checking for a 
lock near the end of a file.

    struct flock sflp;
    sflp.l_start = 2147483345;
    sflp.l_len = 302;
    /* 2147483345 + 302 == 2147483647 (this should not overflow 31 bits) */
    /* 2^31 ==             2147483648 */
    fcntl_stat = fcntl(fd, F_GETLK, &sflp);


The patch also contains a fix to handle l_len < 0 which is now defined 
in POSIX 1003.1-2001 from the fcntl man page.

Signed-off-by: John Engel <jhe@us.ibm.com>

-- 
John Engel
IBM Linux Technology Center


[-- Attachment #2: compat_sys_fcntl64.patch --]
[-- Type: text/x-patch, Size: 1272 bytes --]

diff -ruN linux-2.6.8.1-clean/fs/compat.c linux-2.6.8.1/fs/compat.c
--- linux-2.6.8.1-clean/fs/compat.c	2004-08-14 05:55:31.000000000 -0500
+++ linux-2.6.8.1/fs/compat.c	2004-09-16 13:52:37.000000000 -0500
@@ -522,8 +522,15 @@
 		ret = sys_fcntl(fd, cmd, (unsigned long)&f);
 		set_fs(old_fs);
 		if ((cmd == F_GETLK) && (ret == 0)) {
+			/* POSIX-2001 now defines negative l_len */
+			if (f.l_len < 0) {
+				f.l_start += f.l_len;
+				f.l_len = -f.l_len;
+			}
+			if (f.l_start < 0)
+				return -EINVAL;
 			if ((f.l_start >= COMPAT_OFF_T_MAX) ||
-			    ((f.l_start + f.l_len) >= COMPAT_OFF_T_MAX))
+			    ((f.l_start + f.l_len) > COMPAT_OFF_T_MAX))
 				ret = -EOVERFLOW;
 			if (ret == 0)
 				ret = put_compat_flock(&f, compat_ptr(arg));
@@ -543,8 +550,15 @@
 				(unsigned long)&f);
 		set_fs(old_fs);
 		if ((cmd == F_GETLK64) && (ret == 0)) {
+			/* POSIX-2001 now defines negative l_len */
+			if (f.l_len < 0) {
+				f.l_start += f.l_len;
+				f.l_len = -f.l_len;
+			}
+			if (f.l_start < 0)
+				return -EINVAL;
 			if ((f.l_start >= COMPAT_LOFF_T_MAX) ||
-			    ((f.l_start + f.l_len) >= COMPAT_LOFF_T_MAX))
+			    ((f.l_start + f.l_len) > COMPAT_LOFF_T_MAX))
 				ret = -EOVERFLOW;
 			if (ret == 0)
 				ret = put_compat_flock64(&f, compat_ptr(arg));

                 reply	other threads:[~2004-09-16 19:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4149F078.7080006@us.ibm.com \
    --to=jhe@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sfr@au1.ibm.com \
    --cc=willy@debian.org \
    /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