NetBSD Problem Report #17483

Received: (qmail 21002 invoked by uid 605); 4 Jul 2002 19:42:42 -0000
Message-Id: <20020704192351.D03F64644@stasis.kittenz.org>
Date: Thu,  4 Jul 2002 20:23:51 +0100 (BST)
From: xs@kittenz.org
Sender: gnats-bugs-owner@netbsd.org
Reply-To: xs@kittenz.org
To: gnats-bugs@gnats.netbsd.org
Subject: /bin/systrace doesn't play nice with openlog(3)
X-Send-Pr-Version: 3.95

>Number:         17483
>Category:       bin
>Synopsis:       /bin/systrace doesn't play nice with openlog(3)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 04 19:43:00 +0000 2002
>Closed-Date:    Fri Jul 01 16:12:56 +0000 2005
>Last-Modified:  Fri Jul 01 16:12:56 +0000 2005
>Originator:     
>Release:        NetBSD 1.6B
>Organization:
>Environment:
/usr/src/bin/systrace/intercept-translate.c:
     $NetBSD: intercept-translate.c,v 1.3 2002/06/18 21:21:17 thorpej Exp $
     $OpenBSD: intercept-translate.c,v 1.2 2002/06/04 19:15:54 deraadt Exp $

System: NetBSD stasis 1.6B NetBSD 1.6B (STASIS) #17: Tue Jul 2 16:46:41 BST 2002 xs@stasis:/usr/src/sys/arch/i386/compile/STASIS i386
Architecture: i386
Machine: i386
>Description:
	openlog(3) connects to /var/run/log with a PF_LOCAL socket. It does
	not fill in the SyslogAddr.sun_len. If sun_len is less than the
	sockaddr size, systrace will decrease the lenght it copies to sun_len.
	In this case, it is reduced to 0, and so nothing is copied. This
	leads to invalid syntax being generated.

>How-To-Repeat:
	systrace -A anything that uses openlog(3) With LOG_NDELAY it will
	fail sooner.
	eg:
#include <syslog.h>

int
main()
{
	openlog("test", LOG_NDELAY, LOG_AUTH);
	return 0;
}

>Fix:

Ignore sa_len. The kernel does. It overwrites sa_len with buflen in
uipc_syscalls.c:sockargs()

Index: intercept-translate.c
===================================================================
RCS file: /cvsroot/basesrc/bin/systrace/intercept-translate.c,v
retrieving revision 1.3
diff -u -r1.3 intercept-translate.c
--- intercept-translate.c	2002/06/18 21:21:17	1.3
+++ intercept-translate.c	2002/07/04 19:29:01
@@ -235,8 +235,6 @@

 	switch (sa->sa_family) {
 	case PF_LOCAL:
-		if (sa->sa_len < len)
-			len = sa->sa_len;
 		if (buflen < len + 1)
 			len = buflen - 1;
 		memcpy(buf, sa->sa_data, len);

>Release-Note:
>Audit-Trail:

From: xs@kittenz.org
To: gnats-bugs@netbsd.org
Cc:  
Subject: Re: bin/17483
Date: Sun, 14 Jul 2002 17:01:34 +0100

 The patch was insufficient.
 Here is OpenBSD's fix against NetBSD's /bin/systrace.

 Index: intercept-translate.c
 ===================================================================
 RCS file: /cvsroot/basesrc/bin/systrace/intercept-translate.c,v
 retrieving revision 1.3
 diff -u -r1.3 intercept-translate.c
 --- intercept-translate.c	2002/06/18 21:21:17	1.3
 +++ intercept-translate.c	2002/07/14 15:46:28
 @@ -223,6 +223,10 @@
  	return (0);
  }

 +#ifndef offsetof
 +#define offsetof(type, elem)	((size_t)&((type *)0)->elem)
 +#endif
 +
  static int
  ic_print_sockaddr(char *buf, size_t buflen, struct intercept_translate *tl)
  {
 @@ -235,8 +239,9 @@

  	switch (sa->sa_family) {
  	case PF_LOCAL:
 -		if (sa->sa_len < len)
 -			len = sa->sa_len;
 +		if (len <= offsetof(struct sockaddr, sa_data))
 +			return -1;
 +		len -= offsetof(struct sockaddr, sa_data);
  		if (buflen < len + 1)
  			len = buflen - 1;
  		memcpy(buf, sa->sa_data, len);


From: Sergey Svishchev <svs+pr@grep.ru>
To: gnats-bugs@gnats.netbsd.org
Cc: xs@kittenz.org
Subject: Re: bin/17483
Date: Sat, 8 Mar 2003 01:01:13 +0300

 Rev. 1.4 of intercept-translate.c includes changes from OpenBSD.

 -- 
 Sergey Svishchev
State-Changed-From-To: open->closed
State-Changed-By: rpaulo@netbsd.org
State-Changed-When: Fri, 01 Jul 2005 16:12:56 +0000
State-Changed-Why:
elad@ says it can be closed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.