Skip to contentSkip to conversation

scheduling while atomic when lseek()ing in /proc/net/tcp

BUG Tore Anderson 4 participants 4 messages Nov 27, 2003 – Nov 30, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

The following code instantly freezes my all of my machines running
any of the beavers:

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <stdio.h>

    int main(void) {
            char buf[8192];
            int fd, chars;
            fd = open("/proc/net/tcp", O_RDONLY);
            chars = read(fd, buf, sizeof(buf));
            lseek(fd, -chars+1, SEEK_CUR);
            close(fd);
            return 0;
    }

It only happens when I lseek() anywhere from -chars+1 to -chars+150
inclusive (in other words, somewhere on the first line). I do not need root to abuse this, which makes it an excellent DoS attack for anyone with an unprivileged account.

I do get an oops, but as I do not have a serial console I'd rather
not transcribe it to paper and post it unless it's crucial to pinpointing the bug.

Signature · 1 line
Tore Anderson
#1 lore raw
Quoted 6 lines · Tore Anderson

Hi,

The following code instantly freezes my all of my machines running
any of the beavers:

The following patch fixed this, but i am _not_not_not sure whether this is the right way to do. Any ideas folks ?

/Raj

seq_file.c renamed from seq_file.c.org +3 -0
@@ -213,6 +213,9 @@
 	switch (origin) {
 		case 1:
 			offset += file->f_pos;
+			if(offset >= 0)
+				retval = file->f_pos = offset;
+			break;
 		case 0:
 			if (offset < 0)
 				break;
#2 lore raw
In reply to Tore Anderson
Quoted 7 lines · Tore Anderson
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <stdio.h>

    int main(void) {
Quoted 8 lines
            char buf[8192];
            int fd, chars;
            fd = open("/proc/net/tcp", O_RDONLY);
            chars = read(fd, buf, sizeof(buf));
            lseek(fd, -chars+1, SEEK_CUR);
            close(fd);
            return 0;
    }

This seems to need initialization of st->state in tcp_seq_start(). tcp_seq_stop() is run with previous st->state, so it call the unneeded unlock etc.

 net/ipv4/tcp_ipv4.c |    1 +
 1 files changed, 1 insertion(+)
net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c~tcp_seq-oops-fix +1 -0
diff -puN net/ipv4/tcp_ipv4.c~tcp_seq-oops-fix net/ipv4/tcp_ipv4.c
@@ -2356,6 +2356,7 @@ static void *tcp_get_idx(struct seq_file
 static void *tcp_seq_start(struct seq_file *seq, loff_t *pos)
 {
 	struct tcp_iter_state* st = seq->private;
+	st->state = TCP_SEQ_STATE_LISTENING;
 	st->num = 0;
 	return *pos ? tcp_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
 }

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw
Quoted 3 lines · On Sat, 29 Nov 2003 02:12:38 +0900 OGAWA Hirofumi…

This seems to need initialization of st->state in tcp_seq_start(). tcp_seq_stop() is run with previous st->state, so it call the unneeded unlock etc.

Patch applied, arigato Hirofumi-san.