From 2057e796df7ddc787086841d2529ebf660e76fe2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 20 Feb 2010 20:28:42 -0500 Subject: [PATCH] Linux: Fix conversion of whole-file locks An overflow bug in commit 49b7bbdd3b45df694fadbef48f9ed99d9bfe07b9 caused whole-file locks to be treated as byte-range locks, which fail to be propagated to other machines. Fix this by setting l_len = 0 for locks that range to the end of the file. FIXES 126561 Change-Id: Ie2dc9d04f33559c73b3b86b64152c549b785f8ad Signed-off-by: Anders Kaseorg Reviewed-on: http://gerrit.openafs.org/1352 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear (cherry picked from commit d3abbebcb0651c5d2c7a3094270fd4f86bea3c1e) Reviewed-on: http://gerrit.openafs.org/1372 --- src/afs/LINUX/osi_vnodeops.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c index 0819dd8566..f661ecd060 100644 --- a/src/afs/LINUX/osi_vnodeops.c +++ b/src/afs/LINUX/osi_vnodeops.c @@ -491,7 +491,10 @@ afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) flock.l_pid = flp->fl_pid; flock.l_whence = 0; flock.l_start = flp->fl_start; - flock.l_len = flp->fl_end - flp->fl_start + 1; + if (flp->fl_end == OFFSET_MAX) + flock.l_len = 0; /* Lock to end of file */ + else + flock.l_len = flp->fl_end - flp->fl_start + 1; /* Safe because there are no large files, yet */ #if defined(F_GETLK64) && (F_GETLK != F_GETLK64) @@ -558,7 +561,10 @@ afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) flp->fl_type = flock.l_type; flp->fl_pid = flock.l_pid; flp->fl_start = flock.l_start; - flp->fl_end = flock.l_start + flock.l_len - 1; + if (flock.l_len == 0) + flp->fl_end = OFFSET_MAX; /* Lock to end of file */ + else + flp->fl_end = flock.l_start + flock.l_len - 1; crfree(credp); return afs_convert_code(code); @@ -577,7 +583,7 @@ afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) { flock.l_pid = flp->fl_pid; flock.l_whence = 0; flock.l_start = 0; - flock.l_len = OFFSET_MAX; + flock.l_len = 0; /* Safe because there are no large files, yet */ #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)