From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kernel.org ([198.145.29.99]:47208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754456AbdKNL3T (ORCPT ); Tue, 14 Nov 2017 06:29:19 -0500 Message-ID: <1510658957.5027.12.camel@kernel.org> Subject: Re: [PATCH] fs/fcntl: restore checking against COMPAT_LOFF_T_MAX for F_GETLK64 From: Jeff Layton To: Vitaly Lipatov Cc: Alexander Viro , "J. Bruce Fields" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig Date: Tue, 14 Nov 2017 06:29:17 -0500 In-Reply-To: <20171114013009.26716-1-lav@etersoft.ru> References: <20171114013009.26716-1-lav@etersoft.ru> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Tue, 2017-11-14 at 04:30 +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 > --- > 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; > +} > + (cc'ing Christoph since he wrote the original patch) This patch looks correct to me, but could we rename it to fixup_compat_flock64 to match the other functions here? Also, I think this should probably go to stable -- any objections? > 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)); -- Jeff Layton