linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/fcntl: restore checking against COMPAT_LOFF_T_MAX for F_GETLK64
@ 2017-11-14  1:30 Vitaly Lipatov
  2017-11-14 11:29 ` Jeff Layton
  2017-11-14 13:47 ` [PATCH v2] " Vitaly Lipatov
  0 siblings, 2 replies; 13+ messages in thread
From: Vitaly Lipatov @ 2017-11-14  1:30 UTC (permalink / raw)
  To: lav
  Cc: Alexander Viro, Jeff Layton, J. Bruce Fields, linux-fsdevel,
	linux-kernel

for fcntl64 with F_GETLK64 we need use checking against COMPAT_LOFF_T_MAX.

Fixes: 94073ad77fff2 "fs/locks: don't mess with the address limit in compat_fcntl64"

Signed-off-by: Vitaly Lipatov <lav@etersoft.ru>
---
 fs/fcntl.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/fs/fcntl.c b/fs/fcntl.c
index 30f47d0..fa17f67 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -604,6 +604,25 @@ static int fixup_compat_flock(struct flock *flock)
 	return 0;
 }
 
+/*
+ * GETLK64 was successful and we need to return the data, but it needs to fit in
+ * the compat structure.
+ * l_start shouldn't be too big, unless the original start + end is greater than
+ * COMPAT_LOFF_T_MAX, in which case the app was asking for trouble, so we return
+ * -EOVERFLOW in that case.  l_len could be too big, in which case we just
+ * truncate it, and only allow the app to see that part of the conflicting lock
+ * that might make sense to it anyway
+ */
+
+static int fixup_compat_l_flock(struct flock *flock)
+{
+	if (flock->l_start > COMPAT_LOFF_T_MAX)
+		return -EOVERFLOW;
+	if (flock->l_len > COMPAT_LOFF_T_MAX)
+		flock->l_len = COMPAT_LOFF_T_MAX;
+	return 0;
+}
+
 COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
 		       compat_ulong_t, arg)
 {
@@ -644,7 +663,7 @@ COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
 		err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);
 		if (err)
 			break;
-		err = fixup_compat_flock(&flock);
+		err = fixup_compat_l_flock(&flock);
 		if (err)
 			return err;
 		err = put_compat_flock64(&flock, compat_ptr(arg));
-- 
2.10.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-11-15 13:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-14  1:30 [PATCH] fs/fcntl: restore checking against COMPAT_LOFF_T_MAX for F_GETLK64 Vitaly Lipatov
2017-11-14 11:29 ` Jeff Layton
2017-11-14 11:37   ` Vitaly Lipatov
2017-11-14 13:47 ` [PATCH v2] " Vitaly Lipatov
2017-11-14 14:06   ` Jeff Layton
2017-11-14 16:48     ` Vitaly Lipatov
2017-11-14 16:48   ` [PATCH v3] " Vitaly Lipatov
2017-11-14 17:17     ` J. Bruce Fields
2017-11-14 19:12     ` Jeff Layton
2017-11-14 19:25       ` Vitaly Lipatov
2017-11-14 20:19         ` Jeff Layton
2017-11-14 21:22           ` Vitaly Lipatov
2017-11-15 13:16             ` Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).