Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jul 2013 17:00:00 GMT
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        freebsd-threads@FreeBSD.org
Subject:   Re: threads/180652: compat32 problem in clock_getcpuclockid2
Message-ID:  <201307191700.r6JH00ST071221@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR threads/180652; it has been noted by GNATS.

From: Konstantin Belousov <kostikbel@gmail.com>
To: Petr Salinger <Petr.Salinger@seznam.cz>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2
Date: Fri, 19 Jul 2013 19:52:30 +0300

 --dA3KA1Bq6vhZBZVs
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Fri, Jul 19, 2013 at 12:09:20PM +0000, Petr Salinger wrote:
 >=20
 > >Number:         180652
 > >Category:       threads
 > >Synopsis:       compat32 problem in clock_getcpuclockid2
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       low
 > >Responsible:    freebsd-threads
 > >State:          open
 > >Quarter:       =20
 > >Keywords:      =20
 > >Date-Required:
 > >Class:          sw-bug
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Fri Jul 19 12:10:00 UTC 2013
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Petr Salinger
 > >Release:        HEAD
 > >Organization:
 > >Environment:
 > GNU/kFreeBSD 10.0-0-amd64
 > >Description:
 > The prototype is
 >=20
 > int clock_getcpuclockid2(id_t id, int which, clockid_t *clock_id);
 >=20
 > In the first argument so far only pid_t and lwpid_t sizes are passed.
 >=20
 > Accroding to sys/_types.h:
 >=20
 > typedef __int64_t       __id_t;
 > typedef __int32_t       __lwpid_t;=20
 > typedef __int32_t       __pid_t;
 > typedef __int32_t       __clockid_t;
 >=20
 > There is no freebsd32_clock_getcpuclockid2 at all.
 > The 64-bit argument is misplaced in compat32.
 >=20
 >=20
 > >How-To-Repeat:
 >=20
 > >Fix:
 >=20
 > The PID/TID is encoded in lower 30 bits of clockid.
 > I.e. whole id_t space cannot be used anyway.
 >=20
 > Please either change signature of syscall to
 >=20
 > int clock_getcpuclockid2(long id, int which, clockid_t *clock_id);
 >=20
 > or provide real
 >=20
 > freebsd32_clock_getcpuclockid2 ();
 
 The following worked for me.
 
 diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/f=
 reebsd32_misc.c
 index dd8d4f7..cfcd83b 100644
 --- a/sys/compat/freebsd32/freebsd32_misc.c
 +++ b/sys/compat/freebsd32/freebsd32_misc.c
 @@ -2332,6 +2332,20 @@ freebsd32_clock_getres(struct thread *td,
  }
 =20
  int
 +freebsd32_clock_getcpuclockid2(struct thread *td,
 +    struct freebsd32_clock_getcpuclockid2_args *uap)
 +{
 +	clockid_t clk_id;
 +	int error;
 +
 +	error =3D kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
 +	    uap->which, &clk_id);
 +	if (error =3D=3D 0)
 +		error =3D copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
 +	return (error);
 +}
 +
 +int
  freebsd32_thr_new(struct thread *td,
  		  struct freebsd32_thr_new_args *uap)
  {
 diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/sy=
 scalls.master
 index bcca754..6cb649f 100644
 --- a/sys/compat/freebsd32/syscalls.master
 +++ b/sys/compat/freebsd32/syscalls.master
 @@ -457,8 +457,9 @@
  244	AUE_NULL	UNIMPL	nosys
  245	AUE_NULL	UNIMPL	nosys
  246	AUE_NULL	UNIMPL	nosys
 -247	AUE_NULL	NOPROTO	{ int clock_getcpuclockid2(id_t id,\
 -					int which, clockid_t *clock_id); }
 +247	AUE_NULL	STD	{ int freebsd32_clock_getcpuclockid2(\
 +				    uint32_t id1, uint32_t id2,\
 +				    int which, clockid_t *clock_id); }
  248	AUE_NULL	UNIMPL	ntp_gettime
  249	AUE_NULL	UNIMPL	nosys
  ; syscall numbers initially used in OpenBSD
 diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
 index 9e0cc06..6b908a0 100644
 --- a/sys/kern/kern_time.c
 +++ b/sys/kern/kern_time.c
 @@ -183,38 +183,46 @@ int
  sys_clock_getcpuclockid2(struct thread *td, struct clock_getcpuclockid2_ar=
 gs *uap)
  {
  	clockid_t clk_id;
 +	int error;
 +
 +	error =3D kern_clock_getcpuclockid2(td, uap->id, uap->which, &clk_id);
 +	if (error =3D=3D 0)
 +		error =3D copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
 +	return (error);
 +}
 +
 +int
 +kern_clock_getcpuclockid2(struct thread *td, id_t id, int which,
 +    clockid_t *clk_id)
 +{
  	struct proc *p;
  	pid_t pid;
  	lwpid_t tid;
  	int error;
 =20
 -	switch(uap->which) {
 +	switch (which) {
  	case CPUCLOCK_WHICH_PID:
 -		if (uap->id !=3D 0) {
 -			p =3D pfind(uap->id);
 +		if (id !=3D 0) {
 +			p =3D pfind(id);
  			if (p =3D=3D NULL)
  				return (ESRCH);
  			error =3D p_cansee(td, p);
  			PROC_UNLOCK(p);
 -			if (error)
 +			if (error !=3D 0)
  				return (error);
 -			pid =3D uap->id;
 +			pid =3D id;
  		} else {
  			pid =3D td->td_proc->p_pid;
  		}
 -		clk_id =3D MAKE_PROCESS_CPUCLOCK(pid);
 -		break;
 +		*clk_id =3D MAKE_PROCESS_CPUCLOCK(pid);
 +		return (0);
  	case CPUCLOCK_WHICH_TID:
 -		if (uap->id =3D=3D 0)
 -			tid =3D td->td_tid;
 -		else
 -			tid =3D uap->id;
 -		clk_id =3D MAKE_THREAD_CPUCLOCK(tid);
 -		break;
 +		tid =3D id =3D=3D 0 ? td->td_tid : id;
 +		*clk_id =3D MAKE_THREAD_CPUCLOCK(tid);
 +		return (0);
  	default:
  		return (EINVAL);
  	}
 -	return (copyout(&clk_id, uap->clock_id, sizeof(clockid_t)));
  }
 =20
  #ifndef _SYS_SYSPROTO_H_
 diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
 index 49e8be1..8901ff3 100644
 --- a/sys/sys/syscallsubr.h
 +++ b/sys/sys/syscallsubr.h
 @@ -76,6 +76,8 @@ int	kern_chmod(struct thread *td, char *path, enum uio_se=
 g pathseg,
  	    int mode);
  int	kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int ui=
 d,
  	    int gid);
 +int	kern_clock_getcpuclockid2(struct thread *td, id_t id, int which,
 +	    clockid_t clk_id);
  int	kern_clock_getres(struct thread *td, clockid_t clock_id,
  	    struct timespec *ts);
  int	kern_clock_gettime(struct thread *td, clockid_t clock_id,
 
 --dA3KA1Bq6vhZBZVs
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.20 (FreeBSD)
 
 iQIcBAEBAgAGBQJR6W7OAAoJEJDCuSvBvK1Bgk0P/jsLFXu7HfjYIYsechP8d+8U
 FNdFrJMhQOFEfeQljwp71eqOE8g6iC0faSPErs/qwEwOjUn4F+CwffrJstcnPiFb
 UPC7pZjP2S12Sd3G1spPdwkphqHIfNdIDWhUxUPclH53au/pcL8d3i5Nj/FpLrNy
 TVgWshgAtBS6/1teKBQsSAtUQR7wje4ZYuCvabfGCsKjANBmKElXvUy2hAoSZM86
 B44dj821JkHsj0Kg9A1BtdZu44fPu99byAmKfhj2Shyg5KGGv2f1m+Urm5yT70th
 KwwPsBewrkmMYEydm7/QxqHMs8yY9CcA1PbWPI2rb2nmZQtamrKUo3AOLjtzo8G+
 0soisBIeOoEkVMNRMq41LGdgs5vbe2WdtUfLek1+ASjTvGGq8JwKgVjG5u4mC4l9
 rvtti0Tc6jh8/dC3a71gv16zh+ehWYq0QD5mY87AlNx+xf4lu1rohuZQdpREni/i
 tnQyYTD0HLx7PS6NlP4ZLnDR2H8Qsr+8DMW8JMKaF4As2orbEsucQoEQEOy7kpOJ
 oKDUBQPCMsybnk64QQwDCPcZfJNxpw7egCzVYQZIzADTkWRvb4ut5hj/rzQonaVg
 ibdCW4A7HK1xxqIUolK+eXaGEfvXX/vJLqUn/dK1lB+XmTXZ6gHgytkk8LwaICaZ
 KryVDPEaF0MAaPylSmbS
 =/PlM
 -----END PGP SIGNATURE-----
 
 --dA3KA1Bq6vhZBZVs--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307191700.r6JH00ST071221>