@@ -1582,6 +1582,25 @@ cpuset_setproc_update_set(struct proc *p, struct cpuset *set)
1582
1582
return (0 );
1583
1583
}
1584
1584
1585
+ /*
1586
+ * In Capability mode, the only accesses that are permitted are to the current
1587
+ * thread and process' CPU and domain sets.
1588
+ */
1589
+ static int
1590
+ cpuset_check_capabilities (struct thread * td , cpulevel_t level , cpuwhich_t which ,
1591
+ id_t id )
1592
+ {
1593
+ if (IN_CAPABILITY_MODE (td )) {
1594
+ if (level != CPU_LEVEL_WHICH )
1595
+ return (ECAPMODE );
1596
+ if (which != CPU_WHICH_TID && which != CPU_WHICH_PID )
1597
+ return (ECAPMODE );
1598
+ if (id != -1 )
1599
+ return (ECAPMODE );
1600
+ }
1601
+ return (0 );
1602
+ }
1603
+
1585
1604
#ifndef _SYS_SYSPROTO_H_
1586
1605
struct cpuset_args {
1587
1606
cpusetid_t * setid ;
@@ -1739,15 +1758,9 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which,
1739
1758
1740
1759
if (cpusetsize < sizeof (cpuset_t ) || cpusetsize > CPU_MAXSIZE / NBBY )
1741
1760
return (ERANGE );
1742
- /* In Capability mode, you can only get your own CPU set. */
1743
- if (IN_CAPABILITY_MODE (td )) {
1744
- if (level != CPU_LEVEL_WHICH )
1745
- return (ECAPMODE );
1746
- if (which != CPU_WHICH_TID && which != CPU_WHICH_PID )
1747
- return (ECAPMODE );
1748
- if (id != -1 )
1749
- return (ECAPMODE );
1750
- }
1761
+ error = cpuset_check_capabilities (td , level , which , id );
1762
+ if (error != 0 )
1763
+ return (error );
1751
1764
size = cpusetsize ;
1752
1765
mask = malloc (size , M_TEMP , M_WAITOK | M_ZERO );
1753
1766
error = cpuset_which (which , id , & p , & ttd , & set );
@@ -1856,15 +1869,9 @@ kern_cpuset_setaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which,
1856
1869
1857
1870
if (cpusetsize < sizeof (cpuset_t ) || cpusetsize > CPU_MAXSIZE / NBBY )
1858
1871
return (ERANGE );
1859
- /* In Capability mode, you can only set your own CPU set. */
1860
- if (IN_CAPABILITY_MODE (td )) {
1861
- if (level != CPU_LEVEL_WHICH )
1862
- return (ECAPMODE );
1863
- if (which != CPU_WHICH_TID && which != CPU_WHICH_PID )
1864
- return (ECAPMODE );
1865
- if (id != -1 )
1866
- return (ECAPMODE );
1867
- }
1872
+ error = cpuset_check_capabilities (td , level , which , id );
1873
+ if (error != 0 )
1874
+ return (error );
1868
1875
mask = malloc (cpusetsize , M_TEMP , M_WAITOK | M_ZERO );
1869
1876
error = copyin (maskp , mask , cpusetsize );
1870
1877
if (error )
@@ -1987,15 +1994,9 @@ kern_cpuset_getdomain(struct thread *td, cpulevel_t level, cpuwhich_t which,
1987
1994
if (domainsetsize < sizeof (domainset_t ) ||
1988
1995
domainsetsize > DOMAINSET_MAXSIZE / NBBY )
1989
1996
return (ERANGE );
1990
- /* In Capability mode, you can only get your own domain set. */
1991
- if (IN_CAPABILITY_MODE (td )) {
1992
- if (level != CPU_LEVEL_WHICH )
1993
- return (ECAPMODE );
1994
- if (which != CPU_WHICH_TID && which != CPU_WHICH_PID )
1995
- return (ECAPMODE );
1996
- if (id != -1 )
1997
- return (ECAPMODE );
1998
- }
1997
+ error = cpuset_check_capabilities (td , level , which , id );
1998
+ if (error != 0 )
1999
+ return (error );
1999
2000
mask = malloc (domainsetsize , M_TEMP , M_WAITOK | M_ZERO );
2000
2001
bzero (& outset , sizeof (outset ));
2001
2002
error = cpuset_which (which , id , & p , & ttd , & set );
@@ -2122,15 +2123,9 @@ kern_cpuset_setdomain(struct thread *td, cpulevel_t level, cpuwhich_t which,
2122
2123
if (policy <= DOMAINSET_POLICY_INVALID ||
2123
2124
policy > DOMAINSET_POLICY_MAX )
2124
2125
return (EINVAL );
2125
- /* In Capability mode, you can only set your own CPU set. */
2126
- if (IN_CAPABILITY_MODE (td )) {
2127
- if (level != CPU_LEVEL_WHICH )
2128
- return (ECAPMODE );
2129
- if (which != CPU_WHICH_TID && which != CPU_WHICH_PID )
2130
- return (ECAPMODE );
2131
- if (id != -1 )
2132
- return (ECAPMODE );
2133
- }
2126
+ error = cpuset_check_capabilities (td , level , which , id );
2127
+ if (error != 0 )
2128
+ return (error );
2134
2129
memset (& domain , 0 , sizeof (domain ));
2135
2130
mask = malloc (domainsetsize , M_TEMP , M_WAITOK | M_ZERO );
2136
2131
error = copyin (maskp , mask , domainsetsize );
0 commit comments