This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Bug report and patch for setsockopt syscall's arguments


Hi, everyone

I found a bug in tapset when trace setsockopt(getsockopt) syscall.

When trace
setsockopt( sockfd,
    SOL_SOCKET,
    SO_REUSEADDR,
    &tmp_optval,
    sizeof(tmp_optval) );
by
probe syscall.setsockopt {
    print(argstr)
}
stap returns
3, ICMP, SO_REUSEADDR, 0x60000fffffd4b5c0, 4

Actually, the second argument(level) should be SOL_SOCKET but not ICMP,
although SOL_SOCKET and ICMP are equal.

Stap should print "SOL_SOCKET" because in linux kernel source
(2.6.22, net/socket.c), the following code means kernel will always do 
SOL_SOCKET when level is set to 1:

1690 asmlinkage long sys_setsockopt(int fd, int level, int optname,
1691                                char __user *optval, int optlen)
1692 {
XXXX         ......
1705         if (level == SOL_SOCKET)
1706                 err =
1707                   sock_setsockopt(sock, level, optname, optval,
1708                       optlen); // Do SOL_SOCKET
1709         else
1710                 err =
1711                   sock->ops->setsockopt(sock, level, optname, optval,
1712                       optlen); // Do other protocal except ICMP

The bug can be fixed by the following patch:

Signed-off-by: "Zhaolei" zhaolei@cn.fujitsu.com

--- aux_syscalls.stp.old        2007-08-07 16:18:45.000000000 +0900
+++ aux_syscalls.stp    2007-08-07 16:19:16.000000000 +0900
@@ -1337,7 +1337,7 @@ function _sockopt_optname_str(opt) {
 /* `man 2 setsockopt` for more information */
 function _sockopt_level_str(l) {
    if(l==0) return "IP"
-   if(l==1) return "ICMP"
+   if(l==1) return "SOL_SOCKET"
    if(l==2) return "IGMP"
    if(l==3) return "GGP"
    if(l==4) return "IP-ENCAP"

The result on modified tapset is
3, SOL_SOCKET, SO_REUSEADDR, 0x60000fffff5875c0, 4

Regards
Zhaolei



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]