* daemon-less kmod & Alpha no-go!
@ 1998-04-20 1:13 Steven N. Hirsch
0 siblings, 0 replies; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-20 1:13 UTC (permalink / raw)
To: adam; +Cc: linux-kernel, axp-list
All,
After doing a full day's battle with the latest version of Adam's
no-daemon kmod on my Alpha UDB, I'm stumped.
By placing printk's in the kernel and printf's in modprobe, I can verify
that modprobe is definitely getting called with the correct arguments.
However, it simply refuses to _do_ anything! In spite of this, the
execve() call gets back a successful status, so no complaints are issued.
The same code works splendidly on my two Intel boxes, so I suspect the
problem is related to the context created by the kernel execve() call on
Alpha linux. And, yes, the stock kmod in 2.1.97 works fine.
I'm open to suggestions for tracking this down.
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
[not found] <Pine.SOL.3.95L.980420092318.3161A-100000@unix12.andrew.cmu.edu>
@ 1998-04-21 1:06 ` Steven N. Hirsch
0 siblings, 0 replies; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-21 1:06 UTC (permalink / raw)
To: Greg Zornetzer; +Cc: adam, linux-kernel, axp-list, Mikael.Pettersson
On Mon, 20 Apr 1998, Greg Zornetzer wrote:
> Hi Steven,
>
> Can you check if the waitpid() call in request_module is actually causing
> a wait, or if it is just being ignored? Happened to some code that I was
> writing very similar to the daemonless kmod patch.
Ok, here's what I used for testing.
echo "/root/kmod_test/kmod_test" > /proc/sys/kernel/modprobe
where kmod_test is this little snippet of do-nothing code:
-------------( cut here )------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
int
main ( int argc, char **argv )
{
char msg[128];
int i;
sprintf(msg, "kmod_test: Invoked as \"kmod_test");
for (i=1; i<argc; i++) {
strcat(msg, " ");
strcat(msg, argv[i]);
}
strcat(msg, "\"\n\n");
syslog(LOG_NOTICE, "%s", msg);
syslog(LOG_NOTICE, "uid = %d\n", getuid());
syslog(LOG_NOTICE, "gid = %d\n\n", getgid());
syslog(LOG_NOTICE, "Sleeping for 5 seconds...");
sleep(5);
syslog(LOG_NOTICE, "Done!\n");
return 0;
}
------------( cut here )------------------------------
plus, this little patch to kmod.c:
--- kmod.c.orig Mon Apr 20 19:56:45 1998
+++ kmod.c Mon Apr 20 20:02:41 1998
@@ -91,7 +91,9 @@
printk(KERN_ERR "kmod: fork failed, errno %d\n", -pid);
return pid;
}
+ printk (KERN_ERR "kmod: About to wait on pid %d\n", pid);
waitpid_result = waitpid(pid, NULL, 0);
+ printk (KERN_ERR "kmod: Done waiting on pid %d\n", pid);
if (waitpid_result != pid) {
printk (KERN_ERR "kmod: waitpid(%d,NULL,0) failed, returning %d.\n",
pid, waitpid_result);
------------------------------------------------------
Here are the results from the logs after trying:
$ mount -t vfat /dev/sda1 /dosC
Apr 20 20:55:14 alpha kernel: kmod: About to wait on pid 425
Apr 20 20:55:14 alpha kmod_test: kmod_test: Invoked as "kmod_test -s -k vfat"
Apr 20 20:55:14 alpha kmod_test: uid = 0
Apr 20 20:55:14 alpha kmod_test: gid = 0
Apr 20 20:55:14 alpha kmod_test: Sleeping for 5 seconds...
(ZZZzzzzz)
Apr 20 20:55:19 alpha kmod_test: Done!
Apr 20 20:55:19 alpha kernel: kmod: Done waiting on pid 425
From my analysis, it looks like:
a) The fake modprobe utility is getting called with the correct arguments
and credentials.
b) wait() is really, truly waiting.
What to try next? Remember, this kernel works just fine with the stock
2.1.97 kmod.
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
[not found] <199804210131.SAA05828@adam.yggdrasil.com>
@ 1998-04-21 2:48 ` Steven N. Hirsch
0 siblings, 0 replies; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-21 2:48 UTC (permalink / raw)
To: Adam J. Richter; +Cc: gaz, shirsch, axp-list, linux-kernel, Mikael.Pettersson
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1100 bytes --]
On Mon, 20 Apr 1998, Adam J. Richter wrote:
> How about trying the following:
(snip)
Actually, needs to be:
#!/bin/sh
echo logging_modprobe $* > /tmp/modprobe.log.$$
/usr/bin/strace /sbin/modprobe $* >> /tmp/modprobe.log.$$ 2>&1
as 'strace' writes to stderr.
Interestingly enough, it starts working when run indirectly <g>. The
trace is attached for loading of the SCSI tape driver.
> You might also try modifying that shell script to echo something
> to standard output, so that you can verify that modprobe has gotten
> init's file descriptors.
I did this. Nothing makes it to the screen or logs.
The success of modprobe under the shell script started me thinking. I
renamed /sbin/modprobe to /sbin/modprobe.real and created a stub
/sbin/modprobe like this:
#!/bin/sh
shift
/sbin/modprobe.real $*
Lo and behold, this does the trick. Sort of bizarre (and possibly a
security hole?), but functional. The question of the hour is:
What is so different about the environment under a subshell?
Perhaps those more knowledgeable can glean some clues from the strace
output.
Steve
[-- Attachment #2: Type: TEXT/PLAIN, Size: 5355 bytes --]
logging_modprobe -s -k char-major-9
execve("/sbin/modprobe", ["/sbin/modprobe", "-s", "-k", "char-major-9"], [/* 8 vars */]) = 0
brk(0) = 0x12010857c
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 0
fstat(0, {st_mode=01, st_size=893125961, ...}) = 0
mmap(0, 4831835984, PROT_READ, 0 /* MAP_??? */, 0, 0) = 0x20000010000
close(0) = 0
open("/lib/libc.so.6.1", O_RDONLY) = 0
mmap(0, 0, PROT_NONE, 0 /* MAP_??? */, 0, 0) = 0x20000012000
mmap(0, 0, PROT_NONE, 0 /* MAP_??? */, 0, 0) = 0x20000014000
munmap(0x20000012000, 8192) = 0
mmap(0, 8192, PROT_NONE, 0 /* MAP_??? */, 0, 0) = 0x20000110000
mprotect(0x200001dc000, 1154856, PROT_NONE) = 0
mmap(0x200002d0000, 1154856, PROT_NONE, 0 /* MAP_??? */, 0, 0) = 0x200002d0000
mmap(0x200002ec000, 1154856, PROT_NONE, 0 /* MAP_??? */, 0, 0) = 0x200002ec000
close(0) = 0
personality(0 /* PER_??? */) = 0
osf_getsysinfo(0x2d, 0x11ffffd90, 0x11ffffe10, 0, 0x300000000) = 0
osf_setsysinfo(0xe, 0x11ffffd90, 0x11ffffe10, 0, 0x300000000) = 0
getxpid() = 547
brk(0) = 0x12010857c
brk(0x1201085bc) = 0x1201085bc
brk(0x12010a000) = 0x12010a000
uname({sys="Linux", node="alpha.fast.net", ...}) = 0
access("/etc/modules.conf", R_OK) = 0
stat("/etc/modules.conf", {st_mode=01, st_size=893125769, ...}) = 0
open("/etc/modules.conf", O_RDONLY) = 0
fstat(0, {st_mode=01, st_size=893125769, ...}) = 0
mmap(0, 4831828304, PROT_WRITE|PROT_EXEC|0x1b0, 0 /* MAP_??? */, 12884901888, 0) = 0x20000012000
read(0, "alias eth0 tulip\nalias eth1 tul"..., 8192) = 117
read(0, "", 8192) = 0
close(0) = 0
munmap(0x20000012000, 8192) = 0
uname({sys="Linux", node="alpha.fast.net", ...}) = 0
stat("/lib/modules/2.1.97/modules.dep", {st_mode=01, st_size=893125769, ...}) = 0
open("/lib/modules/2.1.97/modules.dep", O_RDONLY) = 0
fstat(0, {st_mode=01, st_size=893125769, ...}) = 0
mmap(0, 4831828720, PROT_WRITE|PROT_EXEC|0x1b0, 0 /* MAP_??? */, 12884901888, 0) = 0x20000012000
read(0, "/lib/modules/2.1.97/fs/binfmt_mi"..., 8192) = 680
read(0, "", 8192) = 0
close(0) = 0
munmap(0x20000012000, 8192) = 0
SYS_347(0, 0, 0, 0, 0) = 0
open("/lib/modules/2.1.97/ipv6", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/lib/modules/2.1.97/ipv4", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/lib/modules/2.1.97/cdrom", O_RDONLY|O_NONBLOCK) = 0
fcntl(0, F_SETFD, FD_CLOEXEC) = 0
fstat(0, {st_mode=02, st_size=893125769, ...}) = 0
brk(0x12010e000) = 0x12010e000
lseek(0, 0, SEEK_CUR) = 0
getdents(0, /* 3 entries */, 7944) = 80
stat("/lib/modules/2.1.97/cdrom/.", {st_mode=02, st_size=893125961, ...}) = 0
stat("/lib/modules/2.1.97/cdrom/..", {st_mode=010, st_size=893031120, ...}) = 0
stat("/lib/modules/2.1.97/cdrom/cdrom.o", {st_mode=01, st_size=1524253315, ...}) = 0
access("/lib/modules/2.1.97/cdrom/cdrom.o", R_OK) = 0
lseek(0, 0, SEEK_CUR) = 1024
getdents(0, /* 0 entries */, 7944) = 0
open("/lib/modules/2.1.97/block", O_RDONLY|O_NONBLOCK) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fstat(3, {st_mode=02, st_size=893125769, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
getdents(3, /* 4 entries */, 7944) = 104
stat("/lib/modules/2.1.97/block/.", {st_mode=02, st_size=893125961, ...}) = 0
stat("/lib/modules/2.1.97/block/..", {st_mode=010, st_size=893031120, ...}) = 0
stat("/lib/modules/2.1.97/block/rd.o", {st_mode=01, st_size=1524253315, ...}) = 0
access("/lib/modules/2.1.97/block/rd.o", R_OK) = 0
stat("/lib/modules/2.1.97/block/loop.o", {st_mode=01, st_size=1524253315, ...}) = 0
access("/lib/modules/2.1.97/block/loop.o", R_OK) = 0
lseek(3, 0, SEEK_CUR) = 1024
getdents(3, /* 0 entries */, 7944) = 0
open("/lib/modules/2.1.97/scsi", O_RDONLY|O_NONBLOCK) = 4
fcntl(4, F_SETFD, FD_CLOEXEC) = 0
fstat(4, {st_mode=02, st_size=893125769, ...}) = 0
brk(0x120112000) = 0x120112000
lseek(4, 0, SEEK_CUR) = 0
getdents(4, /* 4 entries */, 7944) = 104
stat("/lib/modules/2.1.97/scsi/.", {st_mode=02, st_size=893125961, ...}) = 0
stat("/lib/modules/2.1.97/scsi/..", {st_mode=010, st_size=893031120, ...}) = 0
stat("/lib/modules/2.1.97/scsi/st.o", {st_mode=01, st_size=1524253315, ...}) = 0
access("/lib/modules/2.1.97/scsi/st.o", R_OK) = 0
SYS_347(0, 0x1, 0x12010f800, 0x400, 0x11ffffcb0) = 0
sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}) = 0
sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}) = 0
sigprocmask(SIG_BLOCK, [CHLD]) = 0 (old mask [])
fork() = 548
wait4(548, [WIFEXITED(s) && WEXITSTATUS(s) == 0], 0, NULL) = 548
sigaction(SIGINT, {SIG_DFL}, NULL) = 0
sigaction(SIGQUIT, {SIG_DFL}, NULL) = 0
sigprocmask(SIG_SETMASK, []) = 0x80000 (old mask [CHLD])
--- SIGCHLD (Child exited) ---
exit(0) = ?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
[not found] <Pine.SOL.3.95L.980420234851.24275A-100000@unix12.andrew.cmu.edu>
@ 1998-04-21 11:17 ` Steven N. Hirsch
0 siblings, 0 replies; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-21 11:17 UTC (permalink / raw)
To: Greg Zornetzer
Cc: Steven N. Hirsch, Adam J. Richter, axp-list, linux-kernel,
Mikael.Pettersson
On Mon, 20 Apr 1998, Greg Zornetzer wrote:
> On Mon, 20 Apr 1998, Steven N. Hirsch wrote:
>
> >
> >
> > On Mon, 20 Apr 1998, Adam J. Richter wrote:
> >
> > > How about trying the following:
> >
> > (snip)
> >
> > Actually, needs to be:
> >
> > #!/bin/sh
> > echo logging_modprobe $* > /tmp/modprobe.log.$$
> > /usr/bin/strace /sbin/modprobe $* >> /tmp/modprobe.log.$$ 2>&1
> >
> > as 'strace' writes to stderr.
> >
> > Interestingly enough, it starts working when run indirectly <g>. The
> > trace is attached for loading of the SCSI tape driver.
> >
> Hmmm - could you try backing off some of the security features that Adam
> put into kmod (the root_paranoia stuff). See if any of that is to
> blame...
The security code is not present in Adam's most recent patch (against
2.1.97).
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
[not found] <E0yRZ3z-000692-00@imladris.demon.co.uk>
@ 1998-04-21 11:51 ` Steven N. Hirsch
1998-04-22 0:27 ` Steven N. Hirsch
0 siblings, 1 reply; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-21 11:51 UTC (permalink / raw)
To: David Woodhouse; +Cc: Mikael.Pettersson, adam, axp-list, linux-kernel
On Tue, 21 Apr 1998, David Woodhouse wrote:
>
>
> What does it do if your script is:
>
> #!/bin/sh
> shift
> exec /sbin/modprobe.real $*
Bingo. It does not work if exec-ed, only when called. What would be the
root cause of this?
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
[not found] <199804210917.LAA00234@zephir.inria.fr>
@ 1998-04-21 12:01 ` Steven N. Hirsch
1998-04-21 19:41 ` Richard Henderson
0 siblings, 1 reply; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-21 12:01 UTC (permalink / raw)
To: Mikael Pettersson; +Cc: adam, shirsch, gaz, axp-list
On Tue, 21 Apr 1998, Mikael Pettersson wrote:
> On Mon, 20 Apr 1998, Steven H. Hirsch wrote:
>
> > #!/bin/sh
> > echo logging_modprobe $* > /tmp/modprobe.log.$$
> > /usr/bin/strace /sbin/modprobe $* >> /tmp/modprobe.log.$$ 2>&1
> >
> > as 'strace' writes to stderr.
> > ...
> > What is so different about the environment under a subshell?
>
> Actually, this shell script does a user-space fork() + exec()
> to run strace. This would most likely mask any problems in
> the kernel thread we created for running the thing.
> For comparison, could you please also try running strace as follows:
>
> #!/bin/sh
> echo logging_modprobe $* > /tmp/modprobe.log.$$
> exec /usr/bin/strace /sbin/modprobe $* >> /tmp/modprobe.log.$$ 2>&1
>
> (I'm also worried that strace itself will fork/exec modprobe,
> but we can't do much about that, can we?)
Veerrry interesting. This is all that ends up in the log file:
logging_modprobe -s -k char-major-9
execve("/sbin/modprobe", ["/sbin/modprobe", "-s", "-k", "char-major-9"], [/* 7 vars */]) = 0
The result suggests that execve() which is not preceeded by a fork fails
(?). Could the kernel be getting confused; perhaps exiting from the
thread instead of running the target?
> Another interesting possibility would be to have the script
> just run insmod on some harmless module, e.g.
>
> #!/bin/sh
> exec /sbin/insmod /lib/modules/2.1.97/misc/loop.o
It seems that anything which we try to 'exec' from the script fails.
> Also, you could try a simpler kmod without any of the safety
> features we put in, i.e. replace exec_modprobe() with:
>
That was one of the first things I tried last weekend - no change.
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
1998-04-21 12:01 ` daemon-less kmod & Alpha no-go! Steven N. Hirsch
@ 1998-04-21 19:41 ` Richard Henderson
1998-04-22 0:53 ` Steven N. Hirsch
0 siblings, 1 reply; 9+ messages in thread
From: Richard Henderson @ 1998-04-21 19:41 UTC (permalink / raw)
To: Steven N. Hirsch; +Cc: Mikael Pettersson, adam, gaz, axp-list
On Tue, Apr 21, 1998 at 08:01:39AM -0400, Steven N. Hirsch wrote:
> It seems that anything which we try to 'exec' from the script fails.
I remember having this trouble when I was first getting kmod
to work on Alpha the first time. I think the problem was with
the signal mask. I do not recall atm why this was a problem.
I havn't looked at the daemonless kmod, but are you by chance
blocking all signals before execing?
r~
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
1998-04-21 11:51 ` Steven N. Hirsch
@ 1998-04-22 0:27 ` Steven N. Hirsch
0 siblings, 0 replies; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-22 0:27 UTC (permalink / raw)
To: adam; +Cc: David Woodhouse, Mikael.Pettersson, axp-list, linux-kernel
All,
I've found the underlying problem with daemonless 'kmod' on Alpha.
Apparently, glibc header changes are to blame. I became suspicious after
noticing that kmod is compiled with __KERNEL__ defined. Turns out to be a
kernel vs. user space disagreement as to the storage type and size of
sigset_t.
The following quick hack brings kmod to life:
*** kmod.c.orig Mon Apr 20 19:56:45 1998
--- kmod.c Tue Apr 21 20:10:42 1998
***************
*** 62,68 ****
the signal just right.
*/
spin_lock_irq(¤t->sigmask_lock);
! sigfillset(¤t->blocked);
spin_unlock_irq(¤t->sigmask_lock);
set_fs(KERNEL_DS); /* Allow execve args to be in kernel space. */
--- 62,68 ----
the signal just right.
*/
spin_lock_irq(¤t->sigmask_lock);
! memset (¤t->blocked, '\0xff', sizeof(current->blocked));
spin_unlock_irq(¤t->sigmask_lock);
set_fs(KERNEL_DS); /* Allow execve args to be in kernel space. */
I get dizzy trying to figure out who is getting which prototype from
where, but maybe someone intimately familiar with the new glibc headers
can suggest a cleaner fix?
Enjoy.
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: daemon-less kmod & Alpha no-go!
1998-04-21 19:41 ` Richard Henderson
@ 1998-04-22 0:53 ` Steven N. Hirsch
0 siblings, 0 replies; 9+ messages in thread
From: Steven N. Hirsch @ 1998-04-22 0:53 UTC (permalink / raw)
To: Richard Henderson; +Cc: Mikael Pettersson, adam, gaz, axp-list
On Tue, 21 Apr 1998, Richard Henderson wrote:
> On Tue, Apr 21, 1998 at 08:01:39AM -0400, Steven N. Hirsch wrote:
> > It seems that anything which we try to 'exec' from the script fails.
>
> I remember having this trouble when I was first getting kmod
> to work on Alpha the first time. I think the problem was with
> the signal mask. I do not recall atm why this was a problem.
Give the man a prize <g>. Yes, that was it precisely. I made another
posting earlier outlining a (kludgy) workaround. I know what fixes it,
but am in the dark about the exact pathology.
> I havn't looked at the daemonless kmod, but are you by chance
> blocking all signals before execing?
Now I am. To make sure we're referring to the same problem, what _should_
be happening, and why?
Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1998-04-22 0:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <199804210917.LAA00234@zephir.inria.fr>
1998-04-21 12:01 ` daemon-less kmod & Alpha no-go! Steven N. Hirsch
1998-04-21 19:41 ` Richard Henderson
1998-04-22 0:53 ` Steven N. Hirsch
[not found] <E0yRZ3z-000692-00@imladris.demon.co.uk>
1998-04-21 11:51 ` Steven N. Hirsch
1998-04-22 0:27 ` Steven N. Hirsch
[not found] <Pine.SOL.3.95L.980420234851.24275A-100000@unix12.andrew.cmu.edu>
1998-04-21 11:17 ` Steven N. Hirsch
[not found] <199804210131.SAA05828@adam.yggdrasil.com>
1998-04-21 2:48 ` Steven N. Hirsch
[not found] <Pine.SOL.3.95L.980420092318.3161A-100000@unix12.andrew.cmu.edu>
1998-04-21 1:06 ` Steven N. Hirsch
1998-04-20 1:13 Steven N. Hirsch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox