2011-06-27 22:17:14

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH 1/4] um: Fix _FORTIFY_SOURCE=2 support for kernel modules

When UML is compiled with _FORTIFY_SOURCE we have to
export all _chk() functions which are used in modules.
For now it's only the case for __sprintf_chk().

Tested-by: Florian Fainelli <[email protected]>
Reported-by: Florian Fainelli <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
---
arch/um/os-Linux/user_syms.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c
index 05f5ea8..45ffe46 100644
--- a/arch/um/os-Linux/user_syms.c
+++ b/arch/um/os-Linux/user_syms.c
@@ -113,3 +113,8 @@ EXPORT_SYMBOL(__stack_smash_handler);

extern long __guard __attribute__((weak));
EXPORT_SYMBOL(__guard);
+
+#ifdef _FORTIFY_SOURCE
+extern int __sprintf_chk(char *str, int flag, size_t strlen, const char *format);
+EXPORT_SYMBOL(__sprintf_chk);
+#endif
--
1.7.5.4


2011-06-27 22:17:27

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH 2/4] um: Add netpoll support

To make netconsole usable on UML, it's ethernet driver
needs netpoll support.

Signed-off-by: Richard Weinberger <[email protected]>
---
arch/um/drivers/net_kern.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index 47d0c37..22745b4 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -262,6 +262,15 @@ static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
return 0;
}

+#ifdef CONFIG_NET_POLL_CONTROLLER
+static void uml_net_poll_controller(struct net_device *dev)
+{
+ disable_irq(dev->irq);
+ uml_net_interrupt(dev->irq, dev);
+ enable_irq(dev->irq);
+}
+#endif
+
static void uml_net_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
@@ -364,6 +373,9 @@ static const struct net_device_ops uml_netdev_ops = {
.ndo_set_mac_address = eth_mac_addr,
.ndo_change_mtu = uml_net_change_mtu,
.ndo_validate_addr = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+ .ndo_poll_controller = uml_net_poll_controller,
+#endif
};

/*
--
1.7.5.4

2011-06-27 22:17:29

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH 3/4] um, exec: remove redundant set_fs(USER_DS)

From: Mathias Krause <[email protected]>

The address limit is already set in flush_old_exec() so this
set_fs(USER_DS) is redundant.

Signed-off-by: Mathias Krause <[email protected]>
Cc: Richard Weinberger <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
---
arch/um/kernel/exec.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/arch/um/kernel/exec.c b/arch/um/kernel/exec.c
index 09bd7b5..939a4a6 100644
--- a/arch/um/kernel/exec.c
+++ b/arch/um/kernel/exec.c
@@ -38,7 +38,6 @@ void flush_thread(void)

void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
{
- set_fs(USER_DS);
PT_REGS_IP(regs) = eip;
PT_REGS_SP(regs) = esp;
}
--
1.7.5.4

2011-06-27 22:15:45

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH 4/4] um: Reinstate kernel version in generated .config

From: Geert Uytterhoeven <[email protected]>

commit 0954828fcbf3bd13d593499b16b901a4e801b0b9 ("kconfig: replace
KERNELVERSION usage by the mainmenu's prompt") made the kernel version
disappear from the generated .config file when configuring for UML.
As UML's Kconfig doesn't have a mainmenu, kconfig falls back to the
default string "Linux Kernel Configuration".

Add a suitable mainmenu to the main UML Kconfig file to fix this.

Signed-off-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
---
arch/um/Kconfig.x86 | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/um/Kconfig.x86 b/arch/um/Kconfig.x86
index 8aae429..d31ecf3 100644
--- a/arch/um/Kconfig.x86
+++ b/arch/um/Kconfig.x86
@@ -1,3 +1,5 @@
+mainmenu "User Mode Linux/$SUBARCH $KERNELVERSION Kernel Configuration"
+
source "arch/um/Kconfig.common"

menu "UML-specific options"
--
1.7.5.4

2011-06-29 15:40:27

by Vitaliy Ivanov

[permalink] [raw]
Subject: Re: [PATCH 1/4] um: Fix _FORTIFY_SOURCE=2 support for kernel modules

On Tue, Jun 28, 2011 at 1:15 AM, Richard Weinberger <[email protected]> wrote:
> When UML is compiled with _FORTIFY_SOURCE we have to
> export all _chk() functions which are used in modules.
> For now it's only the case for __sprintf_chk().
>
> Tested-by: Florian Fainelli <[email protected]>
> Reported-by: Florian Fainelli <[email protected]>
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
> ?arch/um/os-Linux/user_syms.c | ? ?5 +++++
> ?1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c
> index 05f5ea8..45ffe46 100644
> --- a/arch/um/os-Linux/user_syms.c
> +++ b/arch/um/os-Linux/user_syms.c
> @@ -113,3 +113,8 @@ EXPORT_SYMBOL(__stack_smash_handler);
>
> ?extern long __guard __attribute__((weak));
> ?EXPORT_SYMBOL(__guard);
> +
> +#ifdef _FORTIFY_SOURCE
> +extern int __sprintf_chk(char *str, int flag, size_t strlen, const char *format);
> +EXPORT_SYMBOL(__sprintf_chk);
> +#endif
> --

Can you please clarify why it's needed? I use FORTIFY_SOURCES on
Linus' tree UML on Ubuntu w/ no problems and w/o this patch...

Thanks,
Vitaliy

2011-06-29 15:42:35

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH 1/4] um: Fix _FORTIFY_SOURCE=2 support for kernel modules

Am Mittwoch 29 Juni 2011, 17:37:54 schrieb Vitaliy Ivanov:
> On Tue, Jun 28, 2011 at 1:15 AM, Richard Weinberger <[email protected]> wrote:
> > When UML is compiled with _FORTIFY_SOURCE we have to
> > export all _chk() functions which are used in modules.
> > For now it's only the case for __sprintf_chk().
> >
> > Tested-by: Florian Fainelli <[email protected]>
> > Reported-by: Florian Fainelli <[email protected]>
> > Signed-off-by: Richard Weinberger <[email protected]>
> > ---
> > arch/um/os-Linux/user_syms.c | 5 +++++
> > 1 files changed, 5 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c
> > index 05f5ea8..45ffe46 100644
> > --- a/arch/um/os-Linux/user_syms.c
> > +++ b/arch/um/os-Linux/user_syms.c
> > @@ -113,3 +113,8 @@ EXPORT_SYMBOL(__stack_smash_handler);
> >
> > extern long __guard __attribute__((weak));
> > EXPORT_SYMBOL(__guard);
> > +
> > +#ifdef _FORTIFY_SOURCE
> > +extern int __sprintf_chk(char *str, int flag, size_t strlen, const char
> > *format); +EXPORT_SYMBOL(__sprintf_chk);
> > +#endif
> > --
>
> Can you please clarify why it's needed? I use FORTIFY_SOURCES on
> Linus' tree UML on Ubuntu w/ no problems and w/o this patch...

The problem appears only when a UML kernel module is using sprintf().
E.g: CONFIG_UML_WATCHDOG.
Then loading the module will fail because of the missing symbol __sprintf_chk().

Thanks,
//richard

2011-06-29 16:33:37

by Vitaliy Ivanov

[permalink] [raw]
Subject: Re: [PATCH 1/4] um: Fix _FORTIFY_SOURCE=2 support for kernel modules

On Wed, Jun 29, 2011 at 6:42 PM, Richard Weinberger <[email protected]> wrote:
> Am Mittwoch 29 Juni 2011, 17:37:54 schrieb Vitaliy Ivanov:
>> On Tue, Jun 28, 2011 at 1:15 AM, Richard Weinberger <[email protected]> wrote:
>> > When UML is compiled with _FORTIFY_SOURCE we have to
>> > export all _chk() functions which are used in modules.
>> > For now it's only the case for __sprintf_chk().
>> >
>> > Tested-by: Florian Fainelli <[email protected]>
>> > Reported-by: Florian Fainelli <[email protected]>
>> > Signed-off-by: Richard Weinberger <[email protected]>
>> > ---
>> > ?arch/um/os-Linux/user_syms.c | ? ?5 +++++
>> > ?1 files changed, 5 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c
>> > index 05f5ea8..45ffe46 100644
>> > --- a/arch/um/os-Linux/user_syms.c
>> > +++ b/arch/um/os-Linux/user_syms.c
>> > @@ -113,3 +113,8 @@ EXPORT_SYMBOL(__stack_smash_handler);
>> >
>> > ?extern long __guard __attribute__((weak));
>> > ?EXPORT_SYMBOL(__guard);
>> > +
>> > +#ifdef _FORTIFY_SOURCE
>> > +extern int __sprintf_chk(char *str, int flag, size_t strlen, const char
>> > *format); +EXPORT_SYMBOL(__sprintf_chk);
>> > +#endif
>> > --
>>
>> Can you please clarify why it's needed? I use FORTIFY_SOURCES on
>> Linus' tree UML on Ubuntu w/ no problems and w/o this patch...
>
> The problem appears only when a UML kernel module is using sprintf().
> E.g: CONFIG_UML_WATCHDOG.
> Then loading the module will fail because of the missing symbol __sprintf_chk().

Thanks.

Acked-by: Vitaliy Ivanov <[email protected]>

2011-06-29 16:42:46

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 1/4] um: Fix _FORTIFY_SOURCE=2 support for kernel modules

On Wed, Jun 29, 2011 at 17:42, Richard Weinberger <[email protected]> wrote:
> Am Mittwoch 29 Juni 2011, 17:37:54 schrieb Vitaliy Ivanov:
>> On Tue, Jun 28, 2011 at 1:15 AM, Richard Weinberger <[email protected]> wrote:
>> > When UML is compiled with _FORTIFY_SOURCE we have to
>> > export all _chk() functions which are used in modules.
>> > For now it's only the case for __sprintf_chk().
>> >
>> > Tested-by: Florian Fainelli <[email protected]>
>> > Reported-by: Florian Fainelli <[email protected]>
>> > Signed-off-by: Richard Weinberger <[email protected]>
>> > ---
>> >  arch/um/os-Linux/user_syms.c |    5 +++++
>> >  1 files changed, 5 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c
>> > index 05f5ea8..45ffe46 100644
>> > --- a/arch/um/os-Linux/user_syms.c
>> > +++ b/arch/um/os-Linux/user_syms.c
>> > @@ -113,3 +113,8 @@ EXPORT_SYMBOL(__stack_smash_handler);
>> >
>> >  extern long __guard __attribute__((weak));
>> >  EXPORT_SYMBOL(__guard);
>> > +
>> > +#ifdef _FORTIFY_SOURCE
>> > +extern int __sprintf_chk(char *str, int flag, size_t strlen, const char
>> > *format); +EXPORT_SYMBOL(__sprintf_chk);
>> > +#endif
>> > --
>>
>> Can you please clarify why it's needed? I use FORTIFY_SOURCES on
>> Linus' tree UML on Ubuntu w/ no problems and w/o this patch...
>
> The problem appears only when a UML kernel module is using sprintf().
> E.g: CONFIG_UML_WATCHDOG.
> Then loading the module will fail because of the missing symbol __sprintf_chk().

What about changing harddog_user.c to not use sprintf(), but snprintf()?

Besides, the code does look fishy to me:

char pid_buf[sizeof("nnnnn\0")];
sprintf(pid_buf, "%d", os_getpid());

os_getpid() returns int:

int os_getpid(void)
{
return syscall(__NR_getpid);
}

but sys_getpid() returns long.

So we truncate a (possibly 64-bit number) to 32-bit, and format it
in a buffer that has space for 5 chars only...

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

2011-06-29 16:57:57

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH 1/4] um: Fix _FORTIFY_SOURCE=2 support for kernel modules

Am Mittwoch 29 Juni 2011, 18:42:43 schrieb Geert Uytterhoeven:
> On Wed, Jun 29, 2011 at 17:42, Richard Weinberger <[email protected]> wrote:
> > Am Mittwoch 29 Juni 2011, 17:37:54 schrieb Vitaliy Ivanov:
> >> On Tue, Jun 28, 2011 at 1:15 AM, Richard Weinberger <[email protected]> wrote:
> >> > When UML is compiled with _FORTIFY_SOURCE we have to
> >> > export all _chk() functions which are used in modules.
> >> > For now it's only the case for __sprintf_chk().
> >> >
> >> > Tested-by: Florian Fainelli <[email protected]>
> >> > Reported-by: Florian Fainelli <[email protected]>
> >> > Signed-off-by: Richard Weinberger <[email protected]>
> >> > ---
> >> > arch/um/os-Linux/user_syms.c | 5 +++++
> >> > 1 files changed, 5 insertions(+), 0 deletions(-)
> >> >
> >> > diff --git a/arch/um/os-Linux/user_syms.c
> >> > b/arch/um/os-Linux/user_syms.c index 05f5ea8..45ffe46 100644
> >> > --- a/arch/um/os-Linux/user_syms.c
> >> > +++ b/arch/um/os-Linux/user_syms.c
> >> > @@ -113,3 +113,8 @@ EXPORT_SYMBOL(__stack_smash_handler);
> >> >
> >> > extern long __guard __attribute__((weak));
> >> > EXPORT_SYMBOL(__guard);
> >> > +
> >> > +#ifdef _FORTIFY_SOURCE
> >> > +extern int __sprintf_chk(char *str, int flag, size_t strlen, const
> >> > char *format); +EXPORT_SYMBOL(__sprintf_chk);
> >> > +#endif
> >> > --
> >>
> >> Can you please clarify why it's needed? I use FORTIFY_SOURCES on
> >> Linus' tree UML on Ubuntu w/ no problems and w/o this patch...
> >
> > The problem appears only when a UML kernel module is using sprintf().
> > E.g: CONFIG_UML_WATCHDOG.
> > Then loading the module will fail because of the missing symbol
> > __sprintf_chk().
>
> What about changing harddog_user.c to not use sprintf(), but snprintf()?

Then we still have to export __snprintf_chk().

Anyway, replacing all the ugly sprintf() by snprintf() is already on my TODO list.
harddog_user.c is not the only user.

> Besides, the code does look fishy to me:
>
> char pid_buf[sizeof("nnnnn\0")];
> sprintf(pid_buf, "%d", os_getpid());
>
> os_getpid() returns int:
>
> int os_getpid(void)
> {
> return syscall(__NR_getpid);
> }
>
> but sys_getpid() returns long.
>
> So we truncate a (possibly 64-bit number) to 32-bit, and format it
> in a buffer that has space for 5 chars only...

True, the code assumes quite short pid numbers.
Thanks for pointing this out!

The sizeof("nnnnn\0") notation is very error-prone, UML is riddled with it.
It's time to get rid of it.

Thanks,
//richard