linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] binfmt_elf: Fix core dump memory corruption
@ 2018-07-17 16:25 Yu-cheng Yu
  2018-09-25 17:39 ` Yu-cheng Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Yu-cheng Yu @ 2018-07-17 16:25 UTC (permalink / raw)
  To: linux-kernel, x86, H. Peter Anvin, Thomas Gleixner, Ingo Molnar, H.J. Lu
  Cc: Yu-cheng Yu

In fill_note_info(), we kzalloc elf_thread_core_info.notes[] only
for (core_note_type != 0) regsets.  However, in
fill_thread_core_info(), we still leave empty notes and go beyond
the allocated size.  Fix it.

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
---
 fs/binfmt_elf.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 816cc921cf36..6f42e05d2833 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1723,7 +1723,8 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
 				 const struct user_regset_view *view,
 				 long signr, size_t *total)
 {
-	unsigned int i;
+	unsigned int i; /* index to regsets */
+	unsigned int j; /* index to notes */
 	unsigned int regset0_size = regset_size(t->task, &view->regsets[0]);
 
 	/*
@@ -1744,9 +1745,9 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
 
 	/*
 	 * Each other regset might generate a note too.  For each regset
-	 * that has no core_note_type or is inactive, we leave t->notes[i]
-	 * all zero and we'll know to skip writing it later.
+	 * that has no core_note_type or is inactive, we skip it.
 	 */
+	j = 1;
 	for (i = 1; i < view->n; ++i) {
 		const struct user_regset *regset = &view->regsets[i];
 		do_thread_regset_writeback(t->task, regset);
@@ -1763,17 +1764,18 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
 				kfree(data);
 			else {
 				if (regset->core_note_type != NT_PRFPREG)
-					fill_note(&t->notes[i], "LINUX",
+					fill_note(&t->notes[j], "LINUX",
 						  regset->core_note_type,
 						  size, data);
 				else {
 					SET_PR_FPVALID(&t->prstatus,
 							1, regset0_size);
-					fill_note(&t->notes[i], "CORE",
+					fill_note(&t->notes[j], "CORE",
 						  NT_PRFPREG, size, data);
 				}
-				*total += notesize(&t->notes[i]);
+				*total += notesize(&t->notes[j]);
 			}
+			j++;
 		}
 	}
 
-- 
2.17.1


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

* Re: [PATCH] binfmt_elf: Fix core dump memory corruption
  2018-07-17 16:25 [PATCH] binfmt_elf: Fix core dump memory corruption Yu-cheng Yu
@ 2018-09-25 17:39 ` Yu-cheng Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Yu-cheng Yu @ 2018-09-25 17:39 UTC (permalink / raw)
  To: linux-kernel, x86, H. Peter Anvin, Thomas Gleixner, Ingo Molnar,
	H.J. Lu, Oleg Nesterov

On Tue, 2018-07-17 at 09:25 -0700, Yu, Yu-cheng wrote:
> In fill_note_info(), we kzalloc elf_thread_core_info.notes[] only
> for (core_note_type != 0) regsets.  However, in
> fill_thread_core_info(), we still leave empty notes and go beyond
> the allocated size.  Fix it.
> 
> Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
> ---
>  fs/binfmt_elf.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
> index 816cc921cf36..6f42e05d2833 100644
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -1723,7 +1723,8 @@ static int fill_thread_core_info(struct
> elf_thread_core_info *t,
>                                  const struct user_regset_view *view,
>                                  long signr, size_t *total)
>  {
> -       unsigned int i;
> +       unsigned int i; /* index to regsets */
> +       unsigned int j; /* index to notes */
>         unsigned int regset0_size = regset_size(t->task, &view->regsets[0]);
> 
>         /*
> @@ -1744,9 +1745,9 @@ static int fill_thread_core_info(struct
> elf_thread_core_info *t,
> 
>         /*
>          * Each other regset might generate a note too.  For each regset
> -        * that has no core_note_type or is inactive, we leave t->notes[i]
> -        * all zero and we'll know to skip writing it later.
> +        * that has no core_note_type or is inactive, we skip it.
>          */
> +       j = 1;
>         for (i = 1; i < view->n; ++i) {
>                 const struct user_regset *regset = &view->regsets[i];
>                 do_thread_regset_writeback(t->task, regset);
> @@ -1763,17 +1764,18 @@ static int fill_thread_core_info(struct
> elf_thread_core_info *t,
>                                 kfree(data);
>                         else {
>                                 if (regset->core_note_type != NT_PRFPREG)
> -                                       fill_note(&t->notes[i], "LINUX",
> +                                       fill_note(&t->notes[j], "LINUX",
>                                                   regset->core_note_type,
>                                                   size, data);
>                                 else {
>                                         SET_PR_FPVALID(&t->prstatus,
>                                                         1, regset0_size);
> -                                       fill_note(&t->notes[i], "CORE",
> +                                       fill_note(&t->notes[j], "CORE",
>                                                   NT_PRFPREG, size, data);
>                                 }
> -                               *total += notesize(&t->notes[i]);
> +                               *total += notesize(&t->notes[j]);
>                         }
> +                       j++;
>                 }
>         }
> 
> --
> 2.17.1
> 

Hi All,

Any comments on this?

Thanks,
Yu-cheng


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

end of thread, other threads:[~2018-09-25 17:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-17 16:25 [PATCH] binfmt_elf: Fix core dump memory corruption Yu-cheng Yu
2018-09-25 17:39 ` Yu-cheng Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).