ping6 segfault

Denys Vlasenko vda.linux at googlemail.com
Sun Jan 27 23:46:40 UTC 2013


On Friday 25 January 2013 09:48, Joerg Epping wrote:
> Hello,
> 
> on ARM9 machines ping6 still segfaults sometimes. I tracked this down
> to the unpack6/inet_ntop function. I think it's memory alignment
> again.
> Below there is my patch to solve this issue (only tested on ARM9).

This is strange. unpack6() is called on stack-allocated
struct sockaddr_in6 here:

static void ping6(len_and_sockaddr *lsa)
{
        int sockopt;
        struct msghdr msg;
        struct sockaddr_in6 from;
....
                unpack6(G.rcv_packet, c, &from, hoplimit);



and you are saying that then, when "from" is fed to this:

                        inet_ntop(AF_INET6, &from->sin6_addr,
                                        buf, sizeof(buf)),

it segfaults.
But from->sin6_addr is well-aligned within the structure:

struct sockaddr_in6 {
    uint16_t        sin6_family;
    uint16_t        sin6_port;
    uint32_t        sin6_flowinfo;
    struct in6_addr sin6_addr;
    uint32_t        sin6_scope_id;
};


You are merely moving it just to another stack variable:

> +		struct in6_addr target;
> 
>  		if (sz >= sizeof(struct icmp6_hdr) + sizeof(uint32_t))
>  			tp = (uint32_t *) &icmppkt->icmp6_data8[4];
> +		memcpy(&target, &from->sin6_addr, sizeof(struct in6_addr));
>  		unpack_tail(sz, tp,
> -			inet_ntop(AF_INET6, &from->sin6_addr,
> +			inet_ntop(AF_INET6, &target,


Can you experiment with printing &from->sin6_addr a-la

bb_error_msg("from:%p &from->sin6_addr:%p", from, &from->sin6_addr);


?

-- 
vda


More information about the busybox mailing list