2.4.20: MSG_PEEK+MSG_OOB crash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The simple program below crashes recent 2.4 kernels. The network
stack appears to enter a busy loop; messages from the rate limiting
system are emitted to the console:

NET: XXXXX mesages suppressed

(but *no* other messages are printed).

Thomas.

#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <errno.h>

int 
main (int argc, char *argv[])
{
  struct hostent *he;
  int i = 1, s, fd;
  struct sockaddr_in a;
  fd_set rset, wset, eset;
  unsigned char buf[16];
  int len;

  if ((he = gethostbyname ("localhost")) == NULL) {
    perror ("gethostbyname");
    exit (1);
  }
  s = socket (AF_INET, SOCK_STREAM, 0);
  if (s < 0) { perror ("socket"); exit (1); }
  setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof i);
  
  a.sin_family = PF_INET;
  a.sin_port = 0;
  a.sin_addr = *(struct in_addr *)(he->h_addr_list[0]);

  bind (s, (struct sockaddr*) &a, sizeof a);
  listen (s, 10);
  len = sizeof a;
  getsockname (s, (struct sockaddr *) &a, &len);

  switch (fork()) {
    case -1:
      perror ("fork");
      exit (1);
    case 0: /* child: client */
      puts ("@@10");
      close (s);
      s = socket (AF_INET, SOCK_STREAM, 0);
      connect (s, (struct sockaddr*) &a, sizeof a);
      puts ("@@11");
      buf[0] = 1;
      send (s, &buf, 1, MSG_OOB);
      puts ("@@12");

      sleep (2);
      puts ("@@13");
      buf[0] = 2;
      send (s, &buf, 1, 0);
      puts ("@@14");
      return 0;

    default: /* father: server */
      puts ("@@00");
      fd = accept (s, NULL, NULL);
    
      FD_ZERO(&rset);
      FD_ZERO(&wset);
      FD_ZERO(&eset);
      FD_SET (fd, &eset);
    
      puts ("@@01");
      select (fd + 1, &rset, &wset, &eset, NULL);
      puts ("@@02");
      len = recv (fd, &buf, sizeof buf, MSG_PEEK);
      puts ("@@03");
      if (len != 1 || buf[0] != 2)
        { perror ("recv"); exit (1); }
      puts ("@@04");
      while (1) {
        if (wait (&i) == -1 && errno == ECHILD)
          break;
      }
      return 0;
  }
}
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux