免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: sisi8408

Kernel Bug-Vulnerability-Comment library [复制链接]

论坛徽章:
0
发表于 2007-12-22 13:27 |显示全部楼层
两个问题
1、sisi8408 大哥做过实验吗?
2、根据对 sisi8408 大哥的了解,含有中文注释并带有 color=red 的贴子更像是从哪里转过来的,文章来源是哪里呢?

论坛徽章:
0
发表于 2007-12-22 14:33 |显示全部楼层

回复 #71 platinum 的帖子

1、sisi8408 大哥做过实验吗?
//实验的没有,道理上说得通,就应该关注了

2、根据对 sisi8408 大哥的了解,含有中文注释并带有 color=red 的贴子更像是从哪里转过来的,
文章来源是哪里呢?
//没了解好,俺抄谁呐?给大家提个兴而已。

论坛徽章:
0
发表于 2007-12-22 14:55 |显示全部楼层

  1. struct tcphdr {
  2.         __be16        source;
  3.         __be16        dest;
  4.         __be32        seq;
  5.         __be32        ack_seq;
  6. #if defined(__LITTLE_ENDIAN_BITFIELD)
  7.         __u16        res1:4,
  8.                 doff:4,        /* 正解 doff *4 <= 60, 逗你玩 */
  9.                 fin:1,
  10.                 syn:1,
  11.                 rst:1,
  12.                 psh:1,
  13.                 ack:1,
  14.                 urg:1,
  15.                 ece:1,
  16.                 cwr:1;
  17. #elif defined(__BIG_ENDIAN_BITFIELD)
  18.         __u16        doff:4,
  19.                 res1:4,
  20.                 cwr:1,
  21.                 ece:1,
  22.                 urg:1,
  23.                 ack:1,
  24.                 psh:1,
  25.                 rst:1,
  26.                 syn:1,
  27.                 fin:1;
  28. #else
  29. #error        "Adjust your <asm/byteorder.h> defines"
  30. #endif       
  31.         __be16        window;
  32.         __sum16        check;
  33.         __be16        urg_ptr;
  34. };

复制代码

论坛徽章:
0
发表于 2007-12-22 20:52 |显示全部楼层

  1. /* 2007-12-22 20:47 */
  2. static void tcp_options(const struct sk_buff *skb,
  3.                         unsigned int dataoff,
  4.                         struct tcphdr *tcph,
  5.                         struct ip_ct_tcp_state *state)
  6. {
  7.         unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
  8.         unsigned char *ptr;
  9.         int length = (tcph->doff*4) - sizeof(struct tcphdr);
  10.         /*
  11.          * sizeof(buff) = 40
  12.          * length 只能 <= 40 ;)
  13.          */
  14.         if (!length)
  15.                 return;

  16.         ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
  17.                                  length, buff);
  18.        
  19.         /*108byte(20byte<IP>  +
  20.          *          20byte<TCP>  +
  21.          *          40byte<TCP opt> +
  22.          *          28byte<trash>)SYN 包拆成两个碎片:
  23.          * 第一个包:20byte<IP> + 20byte<TCP> + 24byte<TCP opt>
  24.          *           and tcp->doff = 0xf
  25.          * 第二个包:20byte<IP> + 16byte<TCP opt> + 28byte<trash>
  26.          *
  27.          * 这样会迫使 ptr = buff ;/
  28.          * =========================
  29.          * 40byte<TCP opt>这样填充,使得:
  30.          * buff[0 ... 38] = TCPOPT_NOP ;
  31.          * buff[39] = 非 TCPOPT_NOP and TCPOPT_EOL
  32.          */
  33.         BUG_ON(ptr == NULL);

  34.         state->td_scale = state->flags = 0;

  35.         while (length > 0) {
  36.                 /*
  37.                  * when length = 1, ptr = &buff[39], and
  38.                  * while-loop progress...
  39.                  */
  40.                 int opcode = *ptr++;
  41.                 /*
  42.                  * after opcode is read,
  43.                  * ptr = &buff[40]
  44.                  * still ok,
  45.                  */
  46.                 int opsize;

  47.                 switch (opcode) {
  48.                 case TCPOPT_EOL:
  49.                         return;
  50.                 case TCPOPT_NOP:        /* Ref: RFC 793 section 3.1 */
  51.                         length--;
  52.                         continue;
  53.                 default:
  54.                         /*
  55.                          * but when opsize is reading,
  56.                          * buff overflow :?/
  57.                          */
  58.                         opsize = *ptr++;
  59.                        
  60.                         if (opsize < 2) /* "silly options" */
  61.                                 return;
  62.                        
  63.                         if (opsize > length)
  64.                                 break;        /* don't parse partial options */

  65.                         if (opcode == TCPOPT_SACK_PERM
  66.                             && opsize == TCPOLEN_SACK_PERM) {
  67.                                 state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
  68.                         }
  69.                         else if (opcode == TCPOPT_WINDOW
  70.                                  && opsize == TCPOLEN_WINDOW) {
  71.                                 state->td_scale = *(u_int8_t *)ptr;

  72.                                 if (state->td_scale > 14) {
  73.                                         /* See RFC1323 */
  74.                                         state->td_scale = 14;
  75.                                 }
  76.                                 state->flags |= IP_CT_TCP_FLAG_WINDOW_SCALE;
  77.                         }
  78.                         ptr += opsize - 2;
  79.                         length -= opsize;
  80.                 }
  81.         }
  82. }
复制代码

[ 本帖最后由 sisi8408 于 2007-12-22 20:59 编辑 ]

论坛徽章:
0
发表于 2007-12-25 01:10 |显示全部楼层
我也来凑个热闹,这也是一个 BUG 吗?(能力有限,让大家笑话了)

/usr/src/linux/net/ipv4/netfilter/ip_conntrack_proto_tcp.c

  1. /* Print out the private part of the conntrack. */
  2. static int tcp_print_conntrack(struct seq_file *s,
  3.                                const struct ip_conntrack *conntrack)
  4. {
  5.         enum tcp_conntrack state;
  6.         read_lock_bh(&tcp_lock);

  7.         /* 这里 state 可能取到很多值 */
  8.         state = conntrack->proto.tcp.state;
  9.         read_unlock_bh(&tcp_lock);

  10.         /* 这里显示具体的 state */
  11.         return seq_printf(s, "%s ", tcp_conntrack_names[state]);
  12. }
复制代码

  1. static const char *tcp_conntrack_names[] = {
  2.         "NONE",
  3.         "SYN_SENT",
  4.         "SYN_RECV",
  5.         "ESTABLISHED",
  6.         "FIN_WAIT",
  7.         "CLOSE_WAIT",
  8.         "LAST_ACK",
  9.         "TIME_WAIT",
  10.         "CLOSE",
  11.         "LISTEN"
  12. };
复制代码

  1. /* This is exposed to userspace (ctnetlink) */
  2. enum tcp_conntrack {
  3.         TCP_CONNTRACK_NONE,
  4.         TCP_CONNTRACK_SYN_SENT,
  5.         TCP_CONNTRACK_SYN_RECV,
  6.         TCP_CONNTRACK_ESTABLISHED,
  7.         TCP_CONNTRACK_FIN_WAIT,
  8.         TCP_CONNTRACK_CLOSE_WAIT,
  9.         TCP_CONNTRACK_LAST_ACK,
  10.         TCP_CONNTRACK_TIME_WAIT,
  11.         TCP_CONNTRACK_CLOSE,
  12.         TCP_CONNTRACK_LISTEN,
  13.         TCP_CONNTRACK_MAX,          /* 这个没有出现在 tcp_conntrack_names 中 */
  14.         TCP_CONNTRACK_IGNORE     /* 同上 */
  15. };
复制代码

  1. struct ip_ct_tcp
  2. {
  3.         struct ip_ct_tcp_state seen[2]; /* connection parameters per direction */
  4.         u_int8_t        state;          /* state of the connection (enum tcp_conntrack) */
  5.                                                 /* 这里取的可是 enum tcp_conntrack 的值啊? */
  6.         /* For detecting stale connections */
  7.         u_int8_t        last_dir;       /* Direction of the last packet (enum ip_conntrack_dir) */
  8.         u_int8_t        retrans;        /* Number of retransmitted packets */
  9.         u_int8_t        last_index;     /* Index of the last packet */
  10.         u_int32_t       last_seq;       /* Last sequence number seen in dir */
  11.         u_int32_t       last_ack;       /* Last sequence number seen in opposite dir */
  12.         u_int32_t       last_end;       /* Last seq + len */
  13.         u_int16_t       last_win;       /* Last window advertisement seen in dir */
  14. };
复制代码

state = conntrack->proto.tcp.state; 可能取到 TCP_CONNTRACK_MAX 或 TCP_CONNTRACK_IGNORE 吗?
return seq_printf(s, "%s ", tcp_conntrack_names[state]); 会不会溢出?

[ 本帖最后由 platinum 于 2007-12-25 13:28 编辑 ]

论坛徽章:
0
发表于 2007-12-29 22:15 |显示全部楼层

  1. #include <net/snmp.h>
  2. #include <net/ip.h>
  3. #include <net/protocol.h>
  4. #include <net/route.h>
  5. #include <net/xfrm.h>
  6. #include <linux/skbuff.h>
  7. #include <net/sock.h>
  8. #include <net/arp.h>
  9. #include <net/icmp.h>
  10. /* why so much men? linux-2.6.22.5/net/ipv4/ip_output.c
  11. #include <net/checksum.h> */
  12. #include <net/inetpeer.h>
  13. #include <net/checksum.h>
  14. #include <linux/igmp.h>

复制代码

论坛徽章:
0
发表于 2008-01-11 23:00 |显示全部楼层

  1. Hi, Jozsef

  2. Though functions in nf_conntrack_proto_tcp.c never see fragmented packets,
  3. the implementation of the function, ip_frag_reasm() in linux/net/ipv4/ip_fragment.c,
  4. does not make sure that the skb seen in nf_conntrack_proto_tcp.c is linearized,
  5. at least in the case of linux-2.6.22.5 from kernel.org.

  6. Therefore buff overflow is still a problem, if not a vulnerability,
  7. in the function of tcp_options(),
  8. as shown in the following code,

  9. static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev)
  10. {
  11. [...]
  12.     /*
  13.      * head is not linearized,
  14.      * 2008-1-11 22:48 by sisi
  15.      */
  16.     skb_shinfo(head)->frag_list = head->next;

  17.     skb_push(head, head->data - skb_network_header(head));
  18.     atomic_sub(head->truesize, &ip_frag_mem);

  19.     for (fp=head->next; fp; fp = fp->next) {
  20.         head->data_len += fp->len;
  21.         head->len += fp->len;
  22.         if (head->ip_summed != fp->ip_summed)
  23.             head->ip_summed = CHECKSUM_NONE;
  24.         else if (head->ip_summed == CHECKSUM_COMPLETE)
  25.             head->csum = csum_add(head->csum, fp->csum);
  26.         head->truesize += fp->truesize;
  27.         atomic_sub(fp->truesize, &ip_frag_mem);
  28.     }

  29.     head->next = NULL;
  30.     head->dev = dev;
  31.     head->tstamp = qp->stamp;

  32.     iph = ip_hdr(head);
  33.     iph->frag_off = 0;
  34.     iph->tot_len = htons(len);
  35.     IP_INC_STATS_BH(IPSTATS_MIB_REASMOKS);
  36.     qp->fragments = NULL;
  37.     return head;
  38. [...]
  39. }


  40. Best regards,
  41. Jing



  42. 2008/1/4, Jozsef Kadlecsik <[email]kadlec@blackhole.kfki.hu[/email]>:

  43.     Hi,

  44.     On Mon, 24 Dec 2007, jing zhang wrote:

  45.     > buffer overflow is discovered in parsing TCP options,
  46.     > in both tcp_sack() and tcp_options() functions,
  47.     > implemented in nf_conntrack_proto_tcp.c of linux-2.6.22/23.x
  48.     >
  49.     > I think it is possible to crash a netfilter-based firewall box with simply
  50.     > constructed TCP SYN packet.
  51.     [...]
  52.     > /*
  53.     >   If 108-byte TCP SYN packet is received in
  54.     >   the manner of two frags:
  55.     >   farg-I,  20-byte-IP + 20-byte-TCP + 24-byte-TCP_OPT
  56.     >             and tcp->doff assigned to 0xf
  57.     >
  58.     >   farg-II,  20-byte-IP + 16-byte-TCP_OPT + 28-byte-TRASH
  59.     >
  60.     >   then the `ptr' is forcedly assigned to `buff',
  61.     >   and sizeof(buff) is 40-byte.
  62.     > */
  63.     [...]

  64.     Please note, defragmenting happens before conntrack is called. In other
  65.     words these functions never see fragmented packets. Therefore I think
  66.     there is no such problem in nf_conntrack_proto_tcp.c.

  67.     Best regards,
  68.     Jozsef
  69.     -
  70.     E-mail  : [email]kadlec@blackhole.kfki.hu[/email], [email]kadlec@sunserv.kfki.hu[/email]
  71.     PGP key : [url]http://www.kfki.hu/~kadlec/pgp_public_key.txt[/url]
  72.     Address : KFKI Research Institute for Particle and Nuclear Physics
  73.               H-1525 Budapest 114, POB. 49, Hungary
复制代码


though attended, not understood enough yet.

[ 本帖最后由 sisi8408 于 2008-1-13 15:44 编辑 ]

论坛徽章:
0
发表于 2008-01-13 15:45 |显示全部楼层

  1. static int ksoftirqd(void * __bind_cpu)
  2. {
  3.         set_current_state(TASK_INTERRUPTIBLE);
  4.         /*
  5.          * linux-2.6.23.12
  6.          * set_user_nice(current, 1);
  7.          */
  8. [...]
  9. }
复制代码

论坛徽章:
0
发表于 2008-01-13 19:11 |显示全部楼层
sisi8408 大哥帮我看看 75 楼的问题,究竟是怎么一回事呢?

论坛徽章:
0
发表于 2008-01-14 20:26 |显示全部楼层
to platinum

  1. $
  2. $ mkdir /home/platin
  3. $ vim /home/platin/show_buflow.c

  4. #include <linux/module.h>
  5. #include <linux/kernel.h>

  6. #define SHOW_BUF_MAX 3
  7. static char *buff[] = {
  8.         [0 ... SHOW_BUF_MAX -2] = "aaa",
  9.         [SHOW_BUF_MAX -1] = "and what?",
  10. };

  11. static int __init show_buflow_start(void)
  12. {
  13.         int j;
  14.         for (j = 0; j < SHOW_BUF_MAX; j++)
  15.                 printk("%s\n", buff[j]);
  16.         printk("%s\n", buff[j+3]);
  17.         return 0;
  18. }
  19. static void __exit show_buflow_finish(void) {}
  20. module_init(show_buflow_start);
  21. module_exit(show_buflow_finish);

  22. $ echo obj-m=show_buflow.o >>  /home/platin/Makefile
  23. $ make -C /usr/src/linux-2.6.23.12 M=/home/platin modules
  24. $ insmod  /home/platin/show_buflow.ko
  25. $
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP