Skip to content

Commit

Permalink
Merge branch 'freebsd/current/master' into hardened/current/master
Browse files Browse the repository at this point in the history
* freebsd/current/master:
  Consistently ensure that we do not load MXCSR with reserved bits set.
  evdev: Translate KEY_102ND in evdev_scancode2key()
  namecache: fix .. check broken after r324378
  Fixup r325264, take #2
  namecache: ncnegfactor 16 -> 12
  Fixup r325264
  Save on loginclass list locking by checking if caller already uses the struct
  Save on uihash table locking by checking if the caller already uses the struct
  • Loading branch information
opntr-auto committed Nov 1, 2017
2 parents 76e3e8b + a6dcbd1 commit 4d846d1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions sys/amd64/amd64/fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ fpusetregs(struct thread *td, struct savefpu *addr, char *xfpustate,
struct pcb *pcb;
int error;

addr->sv_env.en_mxcsr &= cpu_mxcsr_mask;
pcb = td->td_pcb;
critical_enter();
if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {
Expand Down
6 changes: 2 additions & 4 deletions sys/amd64/amd64/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,6 @@ static int
set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
size_t xfpustate_len)
{
struct savefpu *fpstate;
int error;

if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
Expand All @@ -2260,9 +2259,8 @@ set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
error = 0;
} else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
fpstate = (struct savefpu *)&mcp->mc_fpstate;
fpstate->sv_env.en_mxcsr &= cpu_mxcsr_mask;
error = fpusetregs(td, fpstate, xfpustate, xfpustate_len);
error = fpusetregs(td, (struct savefpu *)&mcp->mc_fpstate,
xfpustate, xfpustate_len);
} else
return (EINVAL);
return (error);
Expand Down
2 changes: 1 addition & 1 deletion sys/dev/evdev/evdev_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static uint16_t evdev_at_set1_scancodes[] = {
KEY_KP8, KEY_KP9, KEY_KPMINUS, KEY_KP4,
KEY_KP5, KEY_KP6, KEY_KPPLUS, KEY_KP1,
KEY_KP2, KEY_KP3, KEY_KP0, KEY_KPDOT,
NONE, NONE, NONE, KEY_F11,
NONE, NONE, KEY_102ND, KEY_F11,
KEY_F12, NONE, NONE, NONE,
NONE, NONE, NONE, NONE,
/* 0x60 - 0x7f */
Expand Down
7 changes: 2 additions & 5 deletions sys/i386/i386/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,6 @@ static int
set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
size_t xfpustate_len)
{
union savefpu *fpstate;
int error;

if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
Expand All @@ -2865,10 +2864,8 @@ set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
error = 0;
} else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
fpstate = (union savefpu *)&mcp->mc_fpstate;
if (cpu_fxsr)
fpstate->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
error = npxsetregs(td, fpstate, xfpustate, xfpustate_len);
error = npxsetregs(td, (union savefpu *)&mcp->mc_fpstate,
xfpustate, xfpustate_len);
} else
return (EINVAL);
return (error);
Expand Down
2 changes: 2 additions & 0 deletions sys/i386/isa/npx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,8 @@ npxsetregs(struct thread *td, union savefpu *addr, char *xfpustate,
if (!hw_float)
return (ENXIO);

if (cpu_fxsr)
addr->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
pcb = td->td_pcb;
critical_enter();
if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {
Expand Down
13 changes: 12 additions & 1 deletion sys/kern/init_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ proc0_init(void *dummy __unused)
struct proc *p;
struct thread *td;
struct ucred *newcred;
struct uidinfo tmpuinfo;
struct loginclass tmplc = {
.lc_name = "",
};
vm_paddr_t pageablemem;
int i;

Expand Down Expand Up @@ -513,10 +517,17 @@ proc0_init(void *dummy __unused)
/* Create credentials. */
newcred = crget();
newcred->cr_ngroups = 1; /* group 0 */
/* A hack to prevent uifind from tripping over NULL pointers. */
curthread->td_ucred = newcred;
tmpuinfo.ui_uid = 1;
newcred->cr_uidinfo = newcred->cr_ruidinfo = &tmpuinfo;
newcred->cr_uidinfo = uifind(0);
newcred->cr_ruidinfo = uifind(0);
newcred->cr_prison = &prison0;
newcred->cr_loginclass = &tmplc;
newcred->cr_loginclass = loginclass_find("default");
/* End hack. creds get properly set later with thread_cow_get_proc */
curthread->td_ucred = NULL;
newcred->cr_prison = &prison0;
proc_set_cred_init(p, newcred);
#ifdef AUDIT
audit_cred_kproc0(newcred);
Expand Down
6 changes: 6 additions & 0 deletions sys/kern/kern_loginclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ loginclass_find(const char *name)
if (name[0] == '\0' || strlen(name) >= MAXLOGNAME)
return (NULL);

lc = curthread->td_ucred->cr_loginclass;
if (strcmp(name, lc->lc_name) == 0) {
loginclass_hold(lc);
return (lc);
}

rw_rlock(&loginclasses_lock);
lc = loginclass_lookup(name);
rw_runlock(&loginclasses_lock);
Expand Down
12 changes: 12 additions & 0 deletions sys/kern/kern_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,18 @@ struct uidinfo *
uifind(uid_t uid)
{
struct uidinfo *new_uip, *uip;
struct ucred *cred;

cred = curthread->td_ucred;
if (cred->cr_uidinfo->ui_uid == uid) {
uip = cred->cr_uidinfo;
uihold(uip);
return (uip);
} else if (cred->cr_ruidinfo->ui_uid == uid) {
uip = cred->cr_ruidinfo;
uihold(uip);
return (uip);
}

rw_rlock(&uihashtbl_lock);
uip = uilookup(uid);
Expand Down
8 changes: 5 additions & 3 deletions sys/kern/vfs_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static __read_mostly LIST_HEAD(nchashhead, namecache) *nchashtbl;/* Hash Table *
static u_long __read_mostly nchash; /* size of hash table */
SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0,
"Size of namecache hash table");
static u_long __read_mostly ncnegfactor = 16; /* ratio of negative entries */
static u_long __read_mostly ncnegfactor = 12; /* ratio of negative entries */
SYSCTL_ULONG(_vfs, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, 0,
"Ratio of negative namecache entries");
static u_long __exclusive_cache_line numneg; /* number of negative entries allocated */
Expand Down Expand Up @@ -1126,7 +1126,8 @@ cache_lookup_nomakeentry(struct vnode *dvp, struct vnode **vpp,
uint32_t hash;
int error;

if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.') {
if (cnp->cn_namelen == 2 &&
cnp->cn_nameptr[0] == '.' && cnp->cn_nameptr[1] == '.') {
counter_u64_add(dotdothits, 1);
dvlp = VP2VNODELOCK(dvp);
dvlp2 = NULL;
Expand Down Expand Up @@ -1219,7 +1220,8 @@ cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
retry:
blp = NULL;
error = 0;
if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.') {
if (cnp->cn_namelen == 2 &&
cnp->cn_nameptr[0] == '.' && cnp->cn_nameptr[1] == '.') {
counter_u64_add(dotdothits, 1);
dvlp = VP2VNODELOCK(dvp);
dvlp2 = NULL;
Expand Down

0 comments on commit 4d846d1

Please sign in to comment.