From owner-freebsd-bugs@FreeBSD.ORG Wed Jan 22 12:10:00 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DABC2573 for ; Wed, 22 Jan 2014 12:10:00 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B5EFC11BD for ; Wed, 22 Jan 2014 12:10:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id s0MCA0WJ043647 for ; Wed, 22 Jan 2014 12:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id s0MCA01J043636; Wed, 22 Jan 2014 12:10:00 GMT (envelope-from gnats) Resent-Date: Wed, 22 Jan 2014 12:10:00 GMT Resent-Message-Id: <201401221210.s0MCA01J043636@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Luc Revardel Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C225F4E2 for ; Wed, 22 Jan 2014 12:01:49 +0000 (UTC) Received: from oldred.freebsd.org (oldred.freebsd.org [IPv6:2001:1900:2254:206a::50:4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AE587117F for ; Wed, 22 Jan 2014 12:01:49 +0000 (UTC) Received: from oldred.freebsd.org ([127.0.1.6]) by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id s0MC1mdh012154 for ; Wed, 22 Jan 2014 12:01:48 GMT (envelope-from nobody@oldred.freebsd.org) Received: (from nobody@localhost) by oldred.freebsd.org (8.14.5/8.14.5/Submit) id s0MC1m2W012130; Wed, 22 Jan 2014 12:01:48 GMT (envelope-from nobody) Message-Id: <201401221201.s0MC1m2W012130@oldred.freebsd.org> Date: Wed, 22 Jan 2014 12:01:48 GMT From: Luc Revardel To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: kern/185996: For IPv6, ipsec_address returns pointer to corrupted data X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jan 2014 12:10:01 -0000 >Number: 185996 >Category: kern >Synopsis: For IPv6, ipsec_address returns pointer to corrupted data >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jan 22 12:10:00 UTC 2014 >Closed-Date: >Last-Modified: >Originator: Luc Revardel >Release: 8.4.0 >Organization: nVidia >Environment: Linux 2.6.24-24-generic #1 SMP Fri Jul 24 22:46:06 UTC 2009 i686 GNU/Linux >Description: When INET6 is defined, ipsec_address returns a pointer to a local variable if called for an AF_INET6 address. The content of this address is unknown after returning from the function. This leads to inconsistent display errors such as in this error message: esp_input_cb: authentication hash mismatch for packet in SA @ƒE«/89a23692 >How-To-Repeat: Simply call ipsec_address() with a pointer to a properly initialized sockaddr_in6. Print the content of returned buffer after the call. struct sockaddr_in6 in6Addr = { /***/}; char *buf; buf = ipsec_address((union sockaddr_union*) &in6Addr); printf("IPv6 Addr: %s\n", buf); >Fix: Move the logic used in inet_ntoa4 (4 static buffers) into ipsec_address so that it'll apply to both ipv4 & ipv6: #ifdef INET /* Return a printable string for the IPv4 address. */ static char * inet_ntoa4(char *buf, struct in_addr ina) { unsigned char *ucp = (unsigned char *) &ina; sprintf(buf, "%d.%d.%d.%d", ucp[0] & 0xff, ucp[1] & 0xff, ucp[2] & 0xff, ucp[3] & 0xff); return (buf); } #endif /* Return a printable string for the address. */ char * ipsec_address(union sockaddr_union* sa) { static char buf[4][INET6_ADDRSTRLEN]; /* ICERA_PORT */ static int i = 3; i = (i + 1) % 4; switch (sa->sa.sa_family) { #ifdef INET case AF_INET: return (inet_ntoa4(buf[i], sa->sin.sin_addr)); #endif /* INET */ #ifdef INET6 case AF_INET6: return (ip6_sprintf(buf[i], &sa->sin6.sin6_addr)); #endif /* INET6 */ default: return ("(unknown address family)"); } } >Release-Note: >Audit-Trail: >Unformatted: