diff mbox

[v2] fs/fcntl: restore checking against COMPAT_LOFF_T_MAX for F_GETLK64

Message ID 20171114134715.21649-1-lav@etersoft.ru (mailing list archive)
State New, archived
Headers show

Commit Message

Vitaly Lipatov Nov. 14, 2017, 1:47 p.m. UTC
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 | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Jeff Layton Nov. 14, 2017, 2:06 p.m. UTC | #1
On Tue, 2017-11-14 at 16:47 +0300, Vitaly Lipatov wrote:
> 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 | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/fcntl.c b/fs/fcntl.c
> index 30f47d0..e9443d9 100644
> --- a/fs/fcntl.c
> +++ b/fs/fcntl.c
> @@ -590,17 +590,17 @@ convert_fcntl_cmd(unsigned int cmd)
>   * GETLK 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_OFF_T_MAX, in which case the app was asking for trouble, so we return
> + * COMPAT_OFF_T_MAX/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_flock(struct flock *flock)
> +static int fixup_compat_flock(struct flock *flock, loff_t off_t_max)
>  {
> -	if (flock->l_start > COMPAT_OFF_T_MAX)
> +	if (flock->l_start > off_t_max)
>  		return -EOVERFLOW;
> -	if (flock->l_len > COMPAT_OFF_T_MAX)
> -		flock->l_len = COMPAT_OFF_T_MAX;
> +	if (flock->l_len > off_t_max)
> +		flock->l_len = off_t_max;
>  	return 0;
>  }
>  
> @@ -631,7 +631,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_flock(&flock, COMPAT_OFF_T_MAX);
>  		if (err)
>  			return err;
>  		err = put_compat_flock(&flock, compat_ptr(arg));
> @@ -644,7 +644,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_flock(&flock, COMPAT_OFF_T_MAX);

I think you want COMPAT_LOFF_T_MAX here? In any case, I'm fine with the
first version, and just renaming the function. I'll plan to push that
one unless you have a reason that we should do it this way.

>  		if (err)
>  			return err;
>  		err = put_compat_flock64(&flock, compat_ptr(arg));

Thanks,
Vitaly Lipatov Nov. 14, 2017, 4:48 p.m. UTC | #2
Jeff Layton писал 14.11.17 17:06:
...
>>  			break;
>> -		err = fixup_compat_flock(&flock);
>> +		err = fixup_compat_flock(&flock, COMPAT_OFF_T_MAX);
> 
> I think you want COMPAT_LOFF_T_MAX here? In any case, I'm fine with the
> first version, and just renaming the function. I'll plan to push that
> one unless you have a reason that we should do it this way.
I would like send v3 with fix the typo you told me. As for me, it is 
more clean than two functions.
Was I wrong with MessageId last time or it is ok to have a new thread 
for every patch version?
diff mbox

Patch

diff --git a/fs/fcntl.c b/fs/fcntl.c
index 30f47d0..e9443d9 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -590,17 +590,17 @@  convert_fcntl_cmd(unsigned int cmd)
  * GETLK 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_OFF_T_MAX, in which case the app was asking for trouble, so we return
+ * COMPAT_OFF_T_MAX/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_flock(struct flock *flock)
+static int fixup_compat_flock(struct flock *flock, loff_t off_t_max)
 {
-	if (flock->l_start > COMPAT_OFF_T_MAX)
+	if (flock->l_start > off_t_max)
 		return -EOVERFLOW;
-	if (flock->l_len > COMPAT_OFF_T_MAX)
-		flock->l_len = COMPAT_OFF_T_MAX;
+	if (flock->l_len > off_t_max)
+		flock->l_len = off_t_max;
 	return 0;
 }
 
@@ -631,7 +631,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_flock(&flock, COMPAT_OFF_T_MAX);
 		if (err)
 			return err;
 		err = put_compat_flock(&flock, compat_ptr(arg));
@@ -644,7 +644,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_flock(&flock, COMPAT_OFF_T_MAX);
 		if (err)
 			return err;
 		err = put_compat_flock64(&flock, compat_ptr(arg));