2001-10-17 07:15:24

by Kamil Iskra

[permalink] [raw]
Subject: Kernel 2.4.12 breaks fuser


Hi,

fuser -n [tcp|udp] no longer works with the Linux kernel 2.4.12. No
processes are printed, even though ports are clearly being used. It used
to work fine with 2.4.10, I don't know about 2.4.11. fuser is version 19,
as found in RH 7.1 (psmisc-19-4).

I know nothing about kernel internals, so I can't pinpoint the exact
change. However, I debugged fuser with gdb and what I found out is that
fuser expects the st_dev field of /proc/pid/fd/* to be 0 for sockets. In
2.4.12 st_dev is 4, at least for TCP sockets, so fuser fails to match the
entries.

I don't know if it's fuser that makes invalid assumptions or if it is a
kernel bug. I guess it's for you guys to decide.

If you reply, please include my e-mail address in Cc, as I'm not on the
kernel list.

Regards,

--
Kamil Iskra http://www.science.uva.nl/~kamil/
Section Computational Science, Faculty of Science, Universiteit van Amsterdam
[email protected] tel. +31 20 525 75 35 fax. +31 20 525 74 90
Kruislaan 403 room F.202 1098 SJ Amsterdam The Netherlands


2001-10-17 08:26:32

by Alexander Viro

[permalink] [raw]
Subject: Re: Kernel 2.4.12 breaks fuser

On Wed, 17 Oct 2001, Kamil Iskra wrote:

> I know nothing about kernel internals, so I can't pinpoint the exact
> change. However, I debugged fuser with gdb and what I found out is that
> fuser expects the st_dev field of /proc/pid/fd/* to be 0 for sockets. In
> 2.4.12 st_dev is 4, at least for TCP sockets, so fuser fails to match the
> entries.
>
> I don't know if it's fuser that makes invalid assumptions or if it is a
> kernel bug. I guess it's for you guys to decide.

fuser. Hmm... OK, our options:

a) revert the last change in net/socket.c (go back to use of
get_empty_inode()). Which we may have to do, since it's -STABLE and
while fuser makes an unwarranted assumption, it was not too unreasonable
to start with. That would be

--- S11-pre1/net/socket.c Sun Sep 30 17:16:28 2001
+++ S10/net/socket.c Sun Sep 23 16:12:10 2001
@@ -440,10 +440,11 @@
struct inode * inode;
struct socket * sock;

- inode = new_inode(sock_mnt->mnt_sb);
+ inode = get_empty_inode();
if (!inode)
return NULL;

+ inode->i_sb = sock_mnt->mnt_sb;
sock = socki_lookup(inode);

inode->i_mode = S_IFSOCK|S_IRWXUGO;

b) fix fuser(1). Notice that it's not hard - all we need is the
patch below (guaranteed to work correctly on earlier kernels - it simply
doesn't make assumptions about the value of st_dev used for sockets).
IMO also worth doing.

--- fuser.c.old Mon Oct 25 14:00:43 1999
+++ fuser.c Wed Oct 17 04:13:56 2001
@@ -676,6 +676,22 @@
return 1;
}

+static dev_t net_dev;
+
+static void find_net_dev(void)
+{
+ int fd = socket(PF_INET, SOCK_DGRAM, 0);
+ struct stat buf;
+ if (fd >= 0 && fstat(fd, &buf) == 0) {
+ net_dev = buf.st_dev;
+ close(fd);
+ return;
+ }
+ if (fd >= 0)
+ close(fd);
+ fprintf(stderr,"can't find sockets' device number");
+}
+

static void usage(void)
{
@@ -718,6 +734,7 @@
list_signals();
return 0;
}
+ find_net_dev();
while (--argc) {
argv++;
if (**argv == '-')
@@ -819,8 +836,8 @@
for (walk = unix_cache; walk; walk = walk->next)
if (walk->fs_dev == st.st_dev && walk->fs_ino ==
st.st_ino)
- enter_item(*argv,flags,sig_number,0,walk->net_ino,
- NULL);
+ enter_item(*argv,flags,sig_number,net_dev,
+ walk->net_ino, NULL);
}
}
else {
@@ -844,7 +861,7 @@
if ((lcl_port == -1 || walk->lcl_port == lcl_port) &&
(!rmt_addr || walk->rmt_addr == rmt_addr) &&
(rmt_port == -1 || walk->rmt_port == rmt_port))
- enter_item(*argv,flags,sig_number,0,walk->ino,
+ enter_item(*argv,flags,sig_number,net_dev,walk->ino,
this_name_space);
}
}

2001-10-17 12:43:07

by csmall

[permalink] [raw]
Subject: Re: Kernel 2.4.12 breaks fuser

On Wed, Oct 17, 2001 at 04:26:42AM -0400, Alexander Viro wrote:
> b) fix fuser(1). Notice that it's not hard - all we need is the
> patch below (guaranteed to work correctly on earlier kernels - it simply
> doesn't make assumptions about the value of st_dev used for sockets).
> IMO also worth doing.

I've made the changes, there is a psmisc 20.2 sitting in the sourceforge
CVS. I will release it tomorrow morning. Thankyou for your patch. The
IPv6 related bug was also there and that is fixed too.

If you want to roll-back your kernel device code, you can do that or
not. It seems the fuser patch doesn't care.
- Craig
--
Craig Small VK2XLZ GnuPG:1C1B D893 1418 2AF4 45EE 95CB C76C E5AC 12CA DFA5
Eye-Net Consulting http://www.eye-net.com.au/ <[email protected]>
MIEEE <[email protected]> Debian developer <[email protected]>