From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryan Mallon Subject: Re: [PATCH] Pass correct length to strnlen_user in fs/exec.c Date: Fri, 09 Sep 2011 10:02:12 +1000 Message-ID: <4E695784.7020303@gmail.com> References: <4E680EBC.4000804@gmail.com> <20110908165213.6ebd844f.akpm@linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Mark Salter , Alexander Viro , linux-fsdevel@vger.kernel.org, "linux-kernel@vger.kernel.org" To: Andrew Morton Return-path: Received: from mail-yx0-f174.google.com ([209.85.213.174]:42146 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756522Ab1IIACS (ORCPT ); Thu, 8 Sep 2011 20:02:18 -0400 In-Reply-To: <20110908165213.6ebd844f.akpm@linux-foundation.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 09/09/11 09:52, Andrew Morton wrote: > On Thu, 08 Sep 2011 10:39:24 +1000 > Ryan Mallon wrote: > >> Replace valid_arg_len function in fs/exec.c with max_arg_len function >> and pass the correct length to strnlen_user. >> >> --- a/fs/exec.c >> +++ b/fs/exec.c >> @@ -296,9 +296,9 @@ err: >> return err; >> } >> >> -static bool valid_arg_len(struct linux_binprm *bprm, long len) >> +static long max_arg_len(struct linux_binprm *bprm) >> { >> - return len <= MAX_ARG_STRLEN; >> + return MAX_ARG_STRLEN; >> } >> >> #else >> @@ -354,9 +354,9 @@ static int __bprm_mm_init(struct linux_binprm *bprm) >> return 0; >> } >> >> -static bool valid_arg_len(struct linux_binprm *bprm, long len) >> +static long max_arg_len(struct linux_binprm *bprm) >> { >> - return len <= bprm->p; >> + return bprm->p; >> } >> >> #endif /* CONFIG_MMU */ >> @@ -474,18 +474,19 @@ static int copy_strings(int argc, struct user_arg_ptr argv, >> const char __user *str; >> int len; >> unsigned long pos; >> + long max_len = max_arg_len(bprm); >> >> ret = -EFAULT; >> str = get_user_arg_ptr(argv, argc); >> if (IS_ERR(str)) >> goto out; >> >> - len = strnlen_user(str, MAX_ARG_STRLEN); >> - if (!len || len > MAX_ARG_STRLEN) >> + len = strnlen_user(str, max_len); >> + if (!len) >> goto out; >> >> ret = -E2BIG; >> - if (!valid_arg_len(bprm, len)) >> + if (len > max_len) >> goto out; >> >> /* We're going to work our way backwords. */ > I'm struggling to find a reason to merge this - it churns code around > rather pointlessly? > That's fine. I originally went looking after a discussion with Mark about the weird strnlen_user semantics and this usage looked incorrect to me because it wasn't obviously checking >= MAX_ARG_STRLEN. The rework I think makes it a bit more clear and passes the correct max length to strnlen_user. Its a bit odd to pass MAX_ARG_STRLEN and then check if it is longer than bprm->len, and I guess assumes that bprm->len is less than MAX_ARG_STRLEN. Feel free to drop the patch if you think it is just churn. ~Ryan