From: "J. Bruce Fields" <bfields@fieldses.org>
To: Jeff Layton <jlayton@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
nfs-ganesha-devel@lists.sourceforge.net,
samba-technical@lists.samba.org
Subject: Re: [PATCH v3 1/6] locks: consolidate common code in the flock_to_posix_lock routines
Date: Wed, 11 Dec 2013 17:57:24 -0500 [thread overview]
Message-ID: <20131211225724.GB3483@fieldses.org> (raw)
In-Reply-To: <20131211225616.GA3483@fieldses.org>
On Wed, Dec 11, 2013 at 05:56:16PM -0500, J. Bruce Fields wrote:
> On Wed, Dec 11, 2013 at 02:07:41PM -0500, Jeff Layton wrote:
> > On Wed, 11 Dec 2013 10:19:31 -0500
> > "J. Bruce Fields" <bfields@fieldses.org> wrote:
> ...
> > > + if (l->l_len > 0)
> > > + fl->fl_end = fl->fl_start + l->l_len - 1;
> > > + else if (l->l_len < 0) {
> > > + fl->fl_end = start - 1;
> >
> > Erm... I think this is not quite right...
> >
> > "start" is uninitialized here. I think this should be:
> >
> > fl->fl_end = fl->fl_start - 1
> >
> > With that too, we can get rid of the local "start" variable. I think
> > this may explain why I'm tripping over the BUG() in locks_remove_file.
>
> Yep.
>
> One other bug: I think l_start < 0 is actually fine in the
> SEEK_CUR/SEEK_END cases.
>
> With that fixed and another comment (though I don't know how much it
> helps), it looks like the below.
Alternatively, maybe we could simplify? (On top of the previous):
commit d4bf5cb021a3ac1ec07530ebda904e262cc89d11
Author: J. Bruce Fields <bfields@redhat.com>
Date: Wed Dec 11 17:42:32 2013 -0500
locks: simplify overflow checking
Or maybe we don't actually care about indicating overflow in the 32-bit
case: sure we could fail if e.g. f_pos+start or f_pos+start+len would
exceed 32-bits, but do we really need to?
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
diff --git a/fs/locks.c b/fs/locks.c
index 39f2ca9..efbf577 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -344,8 +344,8 @@ static int assign_type(struct file_lock *fl, long type)
return 0;
}
-static int flock_to_posix_lock_common(struct file *filp, struct file_lock *fl,
- struct flock64 *l, loff_t offset_max)
+static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
+ struct flock64 *l)
{
switch (l->l_whence) {
case SEEK_SET:
@@ -360,12 +360,12 @@ static int flock_to_posix_lock_common(struct file *filp, struct file_lock *fl,
default:
return -EINVAL;
}
- if (l->l_start > offset_max - fl->fl_start)
+ if (l->l_start > OFFSET_MAX - fl->fl_start)
return -EOVERFLOW;
fl->fl_start += l->l_start;
if (fl->fl_start < 0)
return -EINVAL;
- if (l->l_len > offset_max - fl->fl_start)
+ if (l->l_len > OFFSET_MAX - fl->fl_start)
return -EOVERFLOW;
if (fl->fl_start + l->l_len < 0)
return -EINVAL;
@@ -403,22 +403,9 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl,
.l_len = l->l_len,
};
- /*
- * The use of OFFT_OFFSET_MAX here ensures we return -EOVERFLOW
- * if the start or end of the lock could not be represented as
- * an off_t, following SUSv3.
- */
- return flock_to_posix_lock_common(filp, fl, &ll, OFFT_OFFSET_MAX);
+ return flock64_to_posix_lock(filp, fl, &ll);
}
-#if BITS_PER_LONG == 32
-static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
- struct flock64 *l)
-{
- return flock_to_posix_lock_common(filp, fl, l, OFFSET_MAX);
-}
-#endif
-
/* default lease lock manager operations */
static void lease_break_callback(struct file_lock *fl)
{
next prev parent reply other threads:[~2013-12-11 22:57 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-10 19:17 [PATCH v3 0/6] locks: implement "filp-private" (aka UNPOSIX) locks Jeff Layton
2013-12-10 19:17 ` [PATCH v3 1/6] locks: consolidate common code in the flock_to_posix_lock routines Jeff Layton
2013-12-10 21:22 ` J. Bruce Fields
2013-12-10 23:22 ` J. Bruce Fields
2013-12-11 11:18 ` Jeff Layton
2013-12-11 14:37 ` J. Bruce Fields
2013-12-11 15:19 ` J. Bruce Fields
2013-12-11 16:54 ` Jeff Layton
2013-12-11 16:59 ` J. Bruce Fields
2013-12-11 18:09 ` Jeff Layton
2013-12-11 19:07 ` Jeff Layton
2013-12-11 22:56 ` J. Bruce Fields
2013-12-11 22:57 ` J. Bruce Fields [this message]
2013-12-12 10:43 ` Jeff Layton
2013-12-12 10:44 ` Jeff Layton
2014-01-05 20:39 ` J. Bruce Fields
2014-01-05 20:42 ` [PATCH] locks: fix posix lock range overflow handling J. Bruce Fields
2013-12-10 19:17 ` [PATCH v3 2/6] locks: consolidate checks for compatible filp->f_mode values in setlk handlers Jeff Layton
2013-12-10 19:17 ` [PATCH v3 3/6] locks: rename locks_remove_flock to locks_remove_file Jeff Layton
2013-12-10 19:17 ` [PATCH v3 4/6] locks: show private lock types in /proc/locks Jeff Layton
2013-12-10 19:17 ` [PATCH v3 5/6] locks: report l_pid as -1 for FL_FILE_PVT locks Jeff Layton
2013-12-10 19:31 ` Jeff Layton
2013-12-10 19:41 ` [Nfs-ganesha-devel] " Frank Filz
2013-12-10 19:57 ` Jeff Layton
2013-12-10 19:17 ` [PATCH v3 6/6] locks: add new "private" lock type that is owned by the filp Jeff Layton
2013-12-17 13:31 ` Jeff Layton
2013-12-17 13:37 ` Christoph Hellwig
2013-12-17 13:50 ` Jeff Layton
2013-12-10 19:30 ` [Nfs-ganesha-devel] [PATCH v3 0/6] locks: implement "filp-private" (aka UNPOSIX) locks Frank Filz
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=20131211225724.GB3483@fieldses.org \
--to=bfields@fieldses.org \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nfs-ganesha-devel@lists.sourceforge.net \
--cc=samba-technical@lists.samba.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
all inboxes | Powered by JetHome®