linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exec: Simplify remove_arg_zero() error path
@ 2024-03-09 21:48 Kees Cook
  2024-03-11 16:24 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2024-03-09 21:48 UTC (permalink / raw)
  To: Eric Biederman
  Cc: Kees Cook, Alexander Viro, Christian Brauner, Jan Kara, linux-mm,
	linux-fsdevel, linux-kernel, linux-hardening

We don't need the "out" label any more, so remove "ret" and return
directly on error.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: linux-mm@kvack.org
Cc: linux-fsdevel@vger.kernel.org
---
 fs/exec.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 715e1a8aa4f0..e7d9d6ad980b 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1720,7 +1720,6 @@ static int prepare_binprm(struct linux_binprm *bprm)
  */
 int remove_arg_zero(struct linux_binprm *bprm)
 {
-	int ret = 0;
 	unsigned long offset;
 	char *kaddr;
 	struct page *page;
@@ -1731,10 +1730,8 @@ int remove_arg_zero(struct linux_binprm *bprm)
 	do {
 		offset = bprm->p & ~PAGE_MASK;
 		page = get_arg_page(bprm, bprm->p, 0);
-		if (!page) {
-			ret = -EFAULT;
-			goto out;
-		}
+		if (!page)
+			return -EFAULT;
 		kaddr = kmap_local_page(page);
 
 		for (; offset < PAGE_SIZE && kaddr[offset];
@@ -1748,8 +1745,7 @@ int remove_arg_zero(struct linux_binprm *bprm)
 	bprm->p++;
 	bprm->argc--;
 
-out:
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(remove_arg_zero);
 
-- 
2.34.1



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

* Re: [PATCH] exec: Simplify remove_arg_zero() error path
  2024-03-09 21:48 [PATCH] exec: Simplify remove_arg_zero() error path Kees Cook
@ 2024-03-11 16:24 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2024-03-11 16:24 UTC (permalink / raw)
  To: Kees Cook
  Cc: Eric Biederman, Alexander Viro, Christian Brauner, Jan Kara,
	linux-mm, linux-fsdevel, linux-kernel, linux-hardening

On Sat 09-03-24 13:48:30, Kees Cook wrote:
> We don't need the "out" label any more, so remove "ret" and return
> directly on error.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
> Cc: Eric Biederman <ebiederm@xmission.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: linux-mm@kvack.org
> Cc: linux-fsdevel@vger.kernel.org
> ---
>  fs/exec.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index 715e1a8aa4f0..e7d9d6ad980b 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1720,7 +1720,6 @@ static int prepare_binprm(struct linux_binprm *bprm)
>   */
>  int remove_arg_zero(struct linux_binprm *bprm)
>  {
> -	int ret = 0;
>  	unsigned long offset;
>  	char *kaddr;
>  	struct page *page;
> @@ -1731,10 +1730,8 @@ int remove_arg_zero(struct linux_binprm *bprm)
>  	do {
>  		offset = bprm->p & ~PAGE_MASK;
>  		page = get_arg_page(bprm, bprm->p, 0);
> -		if (!page) {
> -			ret = -EFAULT;
> -			goto out;
> -		}
> +		if (!page)
> +			return -EFAULT;
>  		kaddr = kmap_local_page(page);
>  
>  		for (; offset < PAGE_SIZE && kaddr[offset];
> @@ -1748,8 +1745,7 @@ int remove_arg_zero(struct linux_binprm *bprm)
>  	bprm->p++;
>  	bprm->argc--;
>  
> -out:
> -	return ret;
> +	return 0;
>  }
>  EXPORT_SYMBOL(remove_arg_zero);
>  
> -- 
> 2.34.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


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

end of thread, other threads:[~2024-03-11 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09 21:48 [PATCH] exec: Simplify remove_arg_zero() error path Kees Cook
2024-03-11 16:24 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox