NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/54971: sockstat command output incorrect for normal user



The following reply was made to PR bin/54971; it has been noted by GNATS.

From: scole_mail <scole_mail%gmx.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: Christos Zoulas <christos%zoulas.com@localhost>
Subject: Re: bin/54971: sockstat command output incorrect for normal user
Date: Tue, 25 Aug 2020 14:03:48 -0700

 One last item hopefully... I was looking over the *stat programs more
 closely and they all seem to follow some variation of this paradigm with
 setgid/setegid.  I tested it and it worked fine.
 
 If it looks correct, I can check it in or feel free if you'd like to.
 
 Thanks very much
 
 Summary of changes:  (A/? =3D New, R/D =3D Removed, M =3D Modified)
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 M sockstat.c
 
 Apply patch with "cd .../src/usr.bin/sockstat ; patch -s -p0 < .../patchfi=
 le"
 
 Index: sockstat.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /cvsroot/src/usr.bin/sockstat/sockstat.c,v
 retrieving revision 1.22
 diff -b -u -r1.22 sockstat.c
 =2D-- sockstat.c	25 Aug 2020 14:05:17 -0000	1.22
 +++ sockstat.c	25 Aug 2020 20:47:50 -0000
 @@ -121,6 +121,8 @@
  	int ch;
  	size_t i;
  	struct kinfo_proc2 p;
 +	gid_t egid =3D getegid();
 +	setegid(getgid());
 
  	pf_list =3D only =3D 0;
 
 @@ -180,10 +182,13 @@
  		err(1, "init");
 
  	/* Not used, but we set the PK_KMEM flag like this */
 +	setegid(egid);
  	int fd =3D open("/dev/mem", O_RDONLY);
  	if (fd =3D=3D -1)
  		err(EXIT_FAILURE, "Can't open `/dev/mem'");
  	close(fd);
 +	setgid(getgid());
 +
  	if ((portmap !=3D NULL) && (pf_list =3D=3D 0)) {
  		pf_list =3D PF_LIST_INET;
  #ifdef INET6
 


Home | Main Index | Thread Index | Old Index