linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] aout: incorrct use of strncpy fixed.
@ 2019-02-02  0:55 Derek Robson
  2019-02-07 10:25 ` Borislav Petkov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Derek Robson @ 2019-02-02  0:55 UTC (permalink / raw)
  To: tglx, mingo, x86; +Cc: linux-kernel, Derek Robson

Found a bug with the source / dest length
updated to have size limit as the size of dest not size or source.

Signed-off-by: Derek Robson <robsonde@gmail.com>
---
 arch/x86/ia32/ia32_aout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index f65b78d32f5e..1e7f71723ee0 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -157,7 +157,7 @@ static int aout_core_dump(struct coredump_params *cprm)
 	fs = get_fs();
 	set_fs(KERNEL_DS);
 	has_dumped = 1;
-	strncpy(dump.u_comm, current->comm, sizeof(current->comm));
+	strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));
 	dump.u_ar0 = offsetof(struct user32, regs);
 	dump.signal = cprm->siginfo->si_signo;
 	dump_thread32(cprm->regs, &dump);
-- 
2.20.1


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

* Re: [PATCH] aout: incorrct use of strncpy fixed.
  2019-02-02  0:55 [PATCH] aout: incorrct use of strncpy fixed Derek Robson
@ 2019-02-07 10:25 ` Borislav Petkov
  2019-02-07 17:02 ` David Laight
  2019-02-13 11:15 ` [tip:x86/urgent] x86/a.out: Clear the dump structure initially tip-bot for Borislav Petkov
  2 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2019-02-07 10:25 UTC (permalink / raw)
  To: Derek Robson; +Cc: tglx, mingo, x86, linux-kernel

On Sat, Feb 02, 2019 at 01:55:12PM +1300, Derek Robson wrote:
> Found a bug with the source / dest length
> updated to have size limit as the size of dest not size or source.
> 
> Signed-off-by: Derek Robson <robsonde@gmail.com>
> ---
>  arch/x86/ia32/ia32_aout.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
> index f65b78d32f5e..1e7f71723ee0 100644
> --- a/arch/x86/ia32/ia32_aout.c
> +++ b/arch/x86/ia32/ia32_aout.c
> @@ -157,7 +157,7 @@ static int aout_core_dump(struct coredump_params *cprm)
>  	fs = get_fs();
>  	set_fs(KERNEL_DS);
>  	has_dumped = 1;
> -	strncpy(dump.u_comm, current->comm, sizeof(current->comm));
> +	strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));

Are you sure this is correct?

From looking at this, I think there's something else wrong with this
code though.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* RE: [PATCH] aout: incorrct use of strncpy fixed.
  2019-02-02  0:55 [PATCH] aout: incorrct use of strncpy fixed Derek Robson
  2019-02-07 10:25 ` Borislav Petkov
@ 2019-02-07 17:02 ` David Laight
  2019-02-13 11:15 ` [tip:x86/urgent] x86/a.out: Clear the dump structure initially tip-bot for Borislav Petkov
  2 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2019-02-07 17:02 UTC (permalink / raw)
  To: 'Derek Robson', tglx, mingo, x86; +Cc: linux-kernel

From: Derek Robson
> Sent: 02 February 2019 00:55
> 
> Found a bug with the source / dest length
> updated to have size limit as the size of dest not size or source.
> 
> Signed-off-by: Derek Robson <robsonde@gmail.com>
> ---
>  arch/x86/ia32/ia32_aout.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
> index f65b78d32f5e..1e7f71723ee0 100644
> --- a/arch/x86/ia32/ia32_aout.c
> +++ b/arch/x86/ia32/ia32_aout.c
> @@ -157,7 +157,7 @@ static int aout_core_dump(struct coredump_params *cprm)
>  	fs = get_fs();
>  	set_fs(KERNEL_DS);
>  	has_dumped = 1;
> -	strncpy(dump.u_comm, current->comm, sizeof(current->comm));
> +	strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));

That can be right if the destination is guaranteed to be longer than
the source and the source might not be '\0' terminated
(and the target has been zeroed).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [tip:x86/urgent] x86/a.out: Clear the dump structure initially
  2019-02-02  0:55 [PATCH] aout: incorrct use of strncpy fixed Derek Robson
  2019-02-07 10:25 ` Borislav Petkov
  2019-02-07 17:02 ` David Laight
@ 2019-02-13 11:15 ` tip-bot for Borislav Petkov
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Borislav Petkov @ 2019-02-13 11:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, linux-kernel, tglx, hpa, robsonde, bp, matz, stable, torvalds

Commit-ID:  10970e1b4be9c74fce8ab6e3c34a7d718f063f2c
Gitweb:     https://git.kernel.org/tip/10970e1b4be9c74fce8ab6e3c34a7d718f063f2c
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Tue, 12 Feb 2019 14:28:03 +0100
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Wed, 13 Feb 2019 12:10:51 +0100

x86/a.out: Clear the dump structure initially

dump_thread32() in aout_core_dump() does not clear the user32 structure
allocated on the stack as the first thing on function entry.

As a result, the dump.u_comm, dump.u_ar0 and dump.signal which get
assigned before the clearing, get overwritten.

Rename that function to fill_dump() to make it clear what it does and
call it first thing.

This was caught while staring at a patch by Derek Robson
<robsonde@gmail.com>.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Derek Robson <robsonde@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Matz <matz@suse.de>
Cc: x86@kernel.org
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/20190202005512.3144-1-robsonde@gmail.com
---
 arch/x86/ia32/ia32_aout.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index f65b78d32f5e..7dbbe9ffda17 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -51,7 +51,7 @@ static unsigned long get_dr(int n)
 /*
  * fill in the user structure for a core dump..
  */
-static void dump_thread32(struct pt_regs *regs, struct user32 *dump)
+static void fill_dump(struct pt_regs *regs, struct user32 *dump)
 {
 	u32 fs, gs;
 	memset(dump, 0, sizeof(*dump));
@@ -157,10 +157,12 @@ static int aout_core_dump(struct coredump_params *cprm)
 	fs = get_fs();
 	set_fs(KERNEL_DS);
 	has_dumped = 1;
+
+	fill_dump(cprm->regs, &dump);
+
 	strncpy(dump.u_comm, current->comm, sizeof(current->comm));
 	dump.u_ar0 = offsetof(struct user32, regs);
 	dump.signal = cprm->siginfo->si_signo;
-	dump_thread32(cprm->regs, &dump);
 
 	/*
 	 * If the size of the dump file exceeds the rlimit, then see

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

end of thread, other threads:[~2019-02-13 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-02  0:55 [PATCH] aout: incorrct use of strncpy fixed Derek Robson
2019-02-07 10:25 ` Borislav Petkov
2019-02-07 17:02 ` David Laight
2019-02-13 11:15 ` [tip:x86/urgent] x86/a.out: Clear the dump structure initially tip-bot for Borislav Petkov

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).