* [PATCH 1/2] binfmt: Use struct_size()
@ 2023-05-28 16:20 Christophe JAILLET
2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Christophe JAILLET @ 2023-05-28 16:20 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Eric Biederman, Kees Cook
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-fsdevel,
linux-mm
Use struct_size() instead of hand-writing it. It is less verbose, more
robust and more informative.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested on arm
---
fs/binfmt_elf_fdpic.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index d76ad3d4f676..237ce388d06d 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
struct elf32_phdr *phdr;
unsigned long load_addr, stop;
unsigned nloads, tmp;
- size_t size;
int loop, ret;
/* allocate a load map table */
@@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
if (nloads == 0)
return -ELIBBAD;
- size = sizeof(*loadmap) + nloads * sizeof(*seg);
- loadmap = kzalloc(size, GFP_KERNEL);
+ loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL);
if (!loadmap)
return -ENOMEM;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file()
2023-05-28 16:20 [PATCH 1/2] binfmt: Use struct_size() Christophe JAILLET
@ 2023-05-28 16:20 ` Christophe JAILLET
2023-05-28 16:34 ` Eric W. Biederman
2023-05-28 16:32 ` [PATCH 1/2] binfmt: Use struct_size() Eric W. Biederman
2023-05-30 22:52 ` Kees Cook
2 siblings, 1 reply; 5+ messages in thread
From: Christophe JAILLET @ 2023-05-28 16:20 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Eric Biederman, Kees Cook
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-fsdevel,
linux-mm
There is no point in initializing 'load_addr' and 'seg' here, they are both
re-written just before being used below.
Doing so, 'load_addr' can be moved in the #ifdef CONFIG_MMU section.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested on arm, with and without CONFIG_MMU
---
fs/binfmt_elf_fdpic.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 237ce388d06d..1c6c5832af86 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -743,11 +743,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
struct elf32_fdpic_loadmap *loadmap;
#ifdef CONFIG_MMU
struct elf32_fdpic_loadseg *mseg;
+ unsigned long load_addr;
#endif
struct elf32_fdpic_loadseg *seg;
struct elf32_phdr *phdr;
- unsigned long load_addr, stop;
unsigned nloads, tmp;
+ unsigned long stop;
int loop, ret;
/* allocate a load map table */
@@ -768,9 +769,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
loadmap->version = ELF32_FDPIC_LOADMAP_VERSION;
loadmap->nsegs = nloads;
- load_addr = params->load_addr;
- seg = loadmap->segs;
-
/* map the requested LOADs into the memory space */
switch (params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) {
case ELF_FDPIC_FLAG_CONSTDISP:
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] binfmt: Use struct_size()
2023-05-28 16:20 [PATCH 1/2] binfmt: Use struct_size() Christophe JAILLET
2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
@ 2023-05-28 16:32 ` Eric W. Biederman
2023-05-30 22:52 ` Kees Cook
2 siblings, 0 replies; 5+ messages in thread
From: Eric W. Biederman @ 2023-05-28 16:32 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Alexander Viro, Christian Brauner, Kees Cook, linux-kernel,
kernel-janitors, linux-fsdevel, linux-mm
Christophe JAILLET <christophe.jaillet@wanadoo.fr> writes:
> Use struct_size() instead of hand-writing it. It is less verbose, more
> robust and more informative.
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Obviously correct transform.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested on arm
> ---
> fs/binfmt_elf_fdpic.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
> index d76ad3d4f676..237ce388d06d 100644
> --- a/fs/binfmt_elf_fdpic.c
> +++ b/fs/binfmt_elf_fdpic.c
> @@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
> struct elf32_phdr *phdr;
> unsigned long load_addr, stop;
> unsigned nloads, tmp;
> - size_t size;
> int loop, ret;
>
> /* allocate a load map table */
> @@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
> if (nloads == 0)
> return -ELIBBAD;
>
> - size = sizeof(*loadmap) + nloads * sizeof(*seg);
> - loadmap = kzalloc(size, GFP_KERNEL);
> + loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL);
> if (!loadmap)
> return -ENOMEM;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file()
2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
@ 2023-05-28 16:34 ` Eric W. Biederman
0 siblings, 0 replies; 5+ messages in thread
From: Eric W. Biederman @ 2023-05-28 16:34 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Alexander Viro, Christian Brauner, Kees Cook, linux-kernel,
kernel-janitors, linux-fsdevel, linux-mm
Christophe JAILLET <christophe.jaillet@wanadoo.fr> writes:
> There is no point in initializing 'load_addr' and 'seg' here, they are both
> re-written just before being used below.
>
> Doing so, 'load_addr' can be moved in the #ifdef CONFIG_MMU section.
>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Kees do you maybe want to pick these trivial fixes up?
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested on arm, with and without CONFIG_MMU
> ---
> fs/binfmt_elf_fdpic.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
> index 237ce388d06d..1c6c5832af86 100644
> --- a/fs/binfmt_elf_fdpic.c
> +++ b/fs/binfmt_elf_fdpic.c
> @@ -743,11 +743,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
> struct elf32_fdpic_loadmap *loadmap;
> #ifdef CONFIG_MMU
> struct elf32_fdpic_loadseg *mseg;
> + unsigned long load_addr;
> #endif
> struct elf32_fdpic_loadseg *seg;
> struct elf32_phdr *phdr;
> - unsigned long load_addr, stop;
> unsigned nloads, tmp;
> + unsigned long stop;
> int loop, ret;
>
> /* allocate a load map table */
> @@ -768,9 +769,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
> loadmap->version = ELF32_FDPIC_LOADMAP_VERSION;
> loadmap->nsegs = nloads;
>
> - load_addr = params->load_addr;
> - seg = loadmap->segs;
> -
> /* map the requested LOADs into the memory space */
> switch (params->flags & ELF_FDPIC_FLAG_ARRANGEMENT) {
> case ELF_FDPIC_FLAG_CONSTDISP:
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] binfmt: Use struct_size()
2023-05-28 16:20 [PATCH 1/2] binfmt: Use struct_size() Christophe JAILLET
2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
2023-05-28 16:32 ` [PATCH 1/2] binfmt: Use struct_size() Eric W. Biederman
@ 2023-05-30 22:52 ` Kees Cook
2 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2023-05-30 22:52 UTC (permalink / raw)
To: christophe.jaillet, Al Viro, brauner, ebiederm
Cc: Kees Cook, linux-kernel, kernel-janitors, linux-mm, linux-fsdevel
On Sun, 28 May 2023 18:20:24 +0200, Christophe JAILLET wrote:
> Use struct_size() instead of hand-writing it. It is less verbose, more
> robust and more informative.
>
>
Applied to for-next/execve, thanks!
[1/2] binfmt: Use struct_size()
https://git.kernel.org/kees/c/e6302d5a285b
[2/2] binfmt: Slightly simplify elf_fdpic_map_file()
https://git.kernel.org/kees/c/36650a357eac
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-30 22:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-28 16:20 [PATCH 1/2] binfmt: Use struct_size() Christophe JAILLET
2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
2023-05-28 16:34 ` Eric W. Biederman
2023-05-28 16:32 ` [PATCH 1/2] binfmt: Use struct_size() Eric W. Biederman
2023-05-30 22:52 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox