fix 64 bit issue in slirp
PATCH 1/1 fix 64 bit issue in slirp
slirp/ip.h +23 -41
@@ -183,35 +183,31 @@ struct ip_timestamp {#define IP_MSS 576/* default maximum segment size */ -#ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */ -#include <sys/types32.h> -#else #if SIZEOF_CHAR_P ==4 -typedef caddr_t caddr32_t ; -#else -typedef u_int32_t caddr32_t ; -#endif -#endif - -#if SIZEOF_CHAR_P ==4 -typedef struct ipq *ipqp_32 ; -typedef struct ipasfrag *ipasfragp_32 ; +struct mbuf_ptr { +struct mbuf *mptr; +uint32_t dummy; +};#else -typedef caddr32_t ipqp_32 ; -typedef caddr32_t ipasfragp_32 ; +struct mbuf_ptr { +struct mbuf *mptr; +};#endif +struct qlink { +void *next, *prev; +};/* * Overlay for ip header used by other protocols (tcp, udp). */ struct ipovly { -caddr32_t ih_next, ih_prev;/* for protocol sequence q's */ +struct mbuf_ptr ih_mbuf;/* backpointer to mbuf */ u_int8_t ih_x1;/* (unused) */ u_int8_t ih_pr;/* protocol */ u_int16_t ih_len;/* protocol length */ struct in_addr ih_src;/* source internet address */ struct in_addr ih_dst;/* destination internet address */ -}; +} __attribute__((packed));/* * Ip reassembly queue structure. Each fragment
@@ -221,44 +217,30 @@ struct ipovly {* size 28 bytes */ struct ipq { -ipqp_32 next,prev;/* to other reass headers */ +struct qlink frag_link;/* to ip headers of fragments */ +struct qlink ip_link;/* to other reass headers */ u_int8_t ipq_ttl;/* time for reass q to live */ u_int8_t ipq_p;/* protocol of this fragment */ u_int16_t ipq_id;/* sequence id for reassembly */ -ipasfragp_32 ipq_next,ipq_prev; -/* to ip headers of fragments */ struct in_addr ipq_src,ipq_dst; };/* * Ip header, when holding a fragment. * -* Note: ipf_next must be at same offset as ipq_next above +* Note: ipf_link must be at same offset as frag_link above */ struct ipasfrag { -#ifdef WORDS_BIGENDIAN -u_int ip_v:4 , - ip_hl:4 ; -#else -u_int ip_hl:4 , - ip_v:4 ; -#endif -/* BUG : u_int changed to u_int8_t. -* sizeof(u_int)==4 on linux 2.0 -*/ -u_int8_t ipf_mff;/* XXX overlays ip_tos: use low bit -* to avoid destroying tos (PPPDTRuu); -* copied from (ip_off&IP_MF) */ -u_int16_t ip_len; -u_int16_t ip_id; -u_int16_t ip_off; -u_int8_t ip_ttl; -u_int8_t ip_p; -u_int16_t ip_sum; -ipasfragp_32 ipf_next;/* next fragment */ -ipasfragp_32 ipf_prev;/* previous fragment */ +struct qlink ipf_link; +struct ip ipf_ip; }; +#define ipf_off ipf_ip.ip_off +#define ipf_tos ipf_ip.ip_tos +#define ipf_len ipf_ip.ip_len +#define ipf_next ipf_link.next +#define ipf_prev ipf_link.prev +/* * Structure stored in mbuf in inpcb.ip_options * and passed to ip_output when ip options are in use.
slirp/ip_input.c +70 -65
287 lines not on this page · raw message
slirp/misc.c +0 -33
@@ -83,39 +83,6 @@ getouraddr() our_addr.s_addr = loopback_addr.s_addr; } -#if SIZEOF_CHAR_P ==8 - -struct quehead_32 { -u_int32_t qh_link; -u_int32_t qh_rlink; -}; - -inline void -insque_32 (a, b) -void *a; -void *b; -{ - registerstruct quehead_32 *element = (struct quehead_32 *) a; - registerstruct quehead_32 *head = (struct quehead_32 *) b; - element->qh_link = head->qh_link; - head->qh_link = (u_int32_t )element; - element->qh_rlink = (u_int32_t )head; - ((struct quehead_32 *)(element->qh_link))->qh_rlink - = (u_int32_t )element; -} - -inline void -remque_32 (a) -void *a; -{ - registerstruct quehead_32 *element = (struct quehead_32 *) a; - ((struct quehead_32 *)(element->qh_link))->qh_rlink = element->qh_rlink; - ((struct quehead_32 *)(element->qh_rlink))->qh_link = element->qh_link; - element->qh_rlink =0 ; -} - -#endif /* SIZEOF_CHAR_P == 8 */ -struct quehead {struct quehead *qh_link;struct quehead *qh_rlink;
slirp/slirp.c +1 -1
@@ -261,7 +261,7 @@ void slirp_select_fill(int *pnfds,* in the fragment queue, or there are TCP connections active */ do_slowtimo = ((tcb.so_next != &tcb) || - ((struct ipasfrag *)&ipq != (struct ipasfrag *)ipq.next)); + (&ipq.ip_link != ipq.ip_link.next));for (so = tcb.so_next; so != &tcb; so = so_next) { so_next = so->so_next;
slirp/slirp.h +0 -8
@@ -266,14 +266,6 @@ void if_start _P((struct ttys *)); void lprint _P((const char *, ...)); -#if SIZEOF_CHAR_P ==4 -# define insque_32 insque -# define remque_32 remque -#else - void insque_32 _P((void *, void *)); - void remque_32 _P((void *)); -#endif -#ifndef _WIN32#include <netdb.h> #endif
slirp/tcp_input.c +22 -21
120 lines not on this page · raw message
slirp/tcp_subr.c +8 -8
@@ -73,7 +73,7 @@ tcp_template(tp)struct socket *so = tp->t_socket; registerstruct tcpiphdr *n = &tp->t_template; - n->ti_next = n->ti_prev =0 ; + n->ti_mbuf =NULL ; n->ti_x1 =0 ; n->ti_pr =IPPROTO_TCP ; n->ti_len =htons (sizeof (struct tcpiphdr ) -sizeof (struct ip ));
@@ -156,7 +156,7 @@ tcp_respond(tp, ti, m, ack, seq, flags) tlen +=sizeof (struct tcpiphdr ); m->m_len = tlen; - ti->ti_next = ti->ti_prev =0 ; + ti->ti_mbuf =0 ; ti->ti_x1 =0 ; ti->ti_seq =htonl (seq); ti->ti_ack =htonl (ack);
@@ -196,7 +196,7 @@ tcp_newtcpcb(so)return ((struct tcpcb *)0 );memset ((char *) tp,0 ,sizeof (struct tcpcb )); - tp->seg_next = tp->seg_prev = (tcpiphdrp_32 )tp; + tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp; tp->t_maxseg =TCP_MSS ; tp->t_flags =TCP_DO_RFC1323 ? (TF_REQ_SCALE |TF_REQ_TSTMP ) :0 ;
@@ -272,11 +272,11 @@ tcp_close(tp)DEBUG_ARG ("tp = %lx" , (long )tp);/* free the reassembly queue, if any */ - t = (struct tcpiphdr *) tp->seg_next; -while (t != (struct tcpiphdr *)tp) { - t = (struct tcpiphdr *)t->ti_next; - m = (struct mbuf *)REASS_MBUF ((struct tcpiphdr *)t->ti_prev); -remque_32 ((struct tcpiphdr *) t->ti_prev); + t =tcpfrag_list_first (tp); +while (!tcpfrag_list_end (t, tp)) { + t =tcpiphdr_next (t); + m =tcpiphdr_prev (t)->ti_mbuf; +remque (tcpiphdr2qlink (tcpiphdr_prev (t)));m_freem (m); }/* It's static */
slirp/tcp_var.h +2 -23
@@ -40,18 +40,12 @@#include "tcpip.h" #include "tcp_timer.h" -#if SIZEOF_CHAR_P ==4 -typedef struct tcpiphdr *tcpiphdrp_32 ; -#else -typedef u_int32_t tcpiphdrp_32 ; -#endif -/* * Tcp control block, one per tcp; fields: */ struct tcpcb { -tcpiphdrp_32 seg_next;/* sequencing queue */ -tcpiphdrp_32 seg_prev; +struct tcpiphdr *seg_next;/* sequencing queue */ +struct tcpiphdr *seg_prev;short t_state;/* state of this connection */ short t_timer[TCPT_NTIMERS ];/* tcp timers */ short t_rxtshift;/* log(2) of rexmt exp. backoff */
@@ -170,21 +164,6 @@ struct tcpcb {#define TCP_REXMTVAL (tp) \ (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) -/* XXX -* We want to avoid doing m_pullup on incoming packets but that -* means avoiding dtom on the tcp reassembly code. That in turn means -* keeping an mbuf pointer in the reassembly queue (since we might -* have a cluster). As a quick hack, the source & destination -* port numbers (which are no longer needed once we've located the -* tcpcb) are overlayed with an mbuf pointer. -*/ -#if SIZEOF_CHAR_P ==4 -typedef struct mbuf *mbufp_32 ; -#else -typedef u_int32_t mbufp_32 ; -#endif -#define REASS_MBUF (ti) (*(mbufp_32 *)&((ti)->ti_t)) -#ifdef LOG_ENABLED /* * TCP statistics.
slirp/tcpip.h +9 -2
@@ -44,8 +44,7 @@ struct tcpiphdr {struct ipovly ti_i;/* overlaid ip structure */ struct tcphdr ti_t;/* tcp header */ }; -#define ti_next ti_i.ih_next -#define ti_prev ti_i.ih_prev +#define ti_mbuf ti_i.ih_mbuf.mptr#define ti_x1 ti_i.ih_x1#define ti_pr ti_i.ih_pr#define ti_len ti_i.ih_len
@@ -62,6 +61,14 @@ struct tcpiphdr {#define ti_sum ti_t.th_sum#define ti_urp ti_t.th_urp +#define tcpiphdr2qlink (T ) ((struct qlink*)(((char*)(T)) - sizeof(struct qlink))) +#define qlink2tcpiphdr (Q ) ((struct tcpiphdr*)(((char*)(Q)) + sizeof(struct qlink))) +#define tcpiphdr_next (T ) qlink2tcpiphdr(tcpiphdr2qlink(T)->next) +#define tcpiphdr_prev (T ) qlink2tcpiphdr(tcpiphdr2qlink(T)->prev) +#define tcpfrag_list_first (T ) qlink2tcpiphdr((T)->seg_next) +#define tcpfrag_list_end (F ,T ) (tcpiphdr2qlink(F) == (struct qlink*)(T)) +#define tcpfrag_list_empty (T ) ((T)->seg_next == (struct tcpiphdr*)(T)) +/* * Just a clean way to get to the first byte * of the packet
slirp/udp.c +2 -3
@@ -136,8 +136,7 @@ udp_input(m, iphlen)* Checksum extended UDP header and data. */ if (UDPCKSUM && uh->uh_sum) { - ((struct ipovly *)ip)->ih_next =0 ; - ((struct ipovly *)ip)->ih_prev =0 ; +memset (&((struct ipovly *)ip)->ih_mbuf,0 ,sizeof (struct mbuf_ptr )); ((struct ipovly *)ip)->ih_x1 =0 ; ((struct ipovly *)ip)->ih_len = uh->uh_ulen;/* keep uh_sum for ICMP reply
@@ -283,7 +282,7 @@ int udp_output2(struct socket *so, struct mbuf *m,* and addresses and length put into network format. */ ui = mtod(m, struct udpiphdr *); - ui->ui_next = ui->ui_prev =0 ; +memset (&ui->ui_i.ih_mbuf,0 ,sizeof (struct mbuf_ptr )); ui->ui_x1 =0 ; ui->ui_pr =IPPROTO_UDP ; ui->ui_len =htons (m->m_len -sizeof (struct ip ));/* + sizeof (struct udphdr)); */
slirp/udp.h +1 -2
@@ -60,8 +60,7 @@ struct udpiphdr {struct ipovly ui_i;/* overlaid ip structure */ struct udphdr ui_u;/* udp header */ }; -#define ui_next ui_i.ih_next -#define ui_prev ui_i.ih_prev +#define ui_mbuf ui_i.ih_mbuf.mptr#define ui_x1 ui_i.ih_x1#define ui_pr ui_i.ih_pr#define ui_len ui_i.ih_len
--
Gleb.
BTW to reproduce the problem on x86_64 do:
$ export MALLOC_MMAP_THRESHOLD_=10 before starting qemu. This will instruct malloc to use mmap instead of heap for small allocation and qemu will crash in slirp code since mmap returns addresses higher than 4G.
--
Gleb.
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>
Great, but did you really fix all pointer accesses, including the port number stuff?
http://lists.gnu.org/archive/html/qemu-devel/2007-10/msg00542.html
Quoted 7 lines · Blue Swirl
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>Great, but did you really fix all pointer accesses, including the port number stuff?
All that I found obviously :) And yes the one you are talking about is fixed. Look at "struct mbuf_ptr"
--
Gleb.
Quoted 11 lines · Gleb Natapov
Quoted 7 lines · Blue Swirl
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>Great, but did you really fix all pointer accesses, including the port number stuff?
All that I found obviously :) And yes the one you are talking about is
fixed. Look at "structmbuf_ptr"
Excellent! The patch passes my tests. I'll apply it unless there are objections.
This also means that we can finally get rid of the last warnings.
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Gleb Natapov
Quoted 4 lines · Blue Swirl
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Great, but did you really fix all pointer accesses, including the port number stuff?
All that I found obviously :) And yes the one you are talking about is
fixed. Look at "structmbuf_ptr"Excellent! The patch passes my tests. I'll apply it unless there are objections.
Seconded, this thing is what rendered slirp inoperable on AIX64.
Quoted 2 lines
This also means that we can finally get rid of the last warnings.
Signature · 1 line
mailto:[email protected]
Blue Swirl
AppliedQuoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>
Applied, thank you very much. Several people had tried to fix this and failed, but you made it!