Remove caching from getlogin(2).
This caching has existed since the CSRG import, but serves no obvious purpose. Sure, setlogin() is called rarely, but calls to getlogin() should also be infrequent. The required invalidation was not implemented on aarch64, arm, mips, amd riscv so updates would never occur if getlogin() was called before setlogin(). Reported by: Ali Mashtizadeh <ali@mashtizadeh.com> Reviewed by: kib Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14965
This commit is contained in:
parent
b484e3fee4
commit
047a2ef697
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332119
@ -9,7 +9,7 @@ SRCS+= \
|
||||
amd64_set_gsbase.c
|
||||
|
||||
MDASM= vfork.S brk.S cerror.S exect.S getcontext.S \
|
||||
sbrk.S setlogin.S
|
||||
sbrk.S
|
||||
|
||||
# Don't generate default code for these syscalls:
|
||||
NOASM+= vfork.o
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)setlogin.s 5.2 (Berkeley) 4/12/91"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <machine/asm.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl CNAME(_logname_valid) /* in _getlogin() */
|
||||
|
||||
WEAK_REFERENCE(__sys_setlogin, _setlogin)
|
||||
WEAK_REFERENCE(__sys_setlogin, setlogin)
|
||||
ENTRY(__sys_setlogin)
|
||||
mov $SYS_setlogin,%rax
|
||||
KERNCALL
|
||||
jb HIDENAME(cerror)
|
||||
movl $0,CNAME(_logname_valid)(%rip)
|
||||
ret /* setlogin(name) */
|
||||
END(__sys_setlogin)
|
||||
|
||||
.section .note.GNU-stack,"",%progbits
|
@ -47,62 +47,33 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include "libc_private.h"
|
||||
|
||||
#define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex)
|
||||
#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex)
|
||||
|
||||
extern int _getlogin(char *, int);
|
||||
|
||||
int _logname_valid __hidden; /* known to setlogin() */
|
||||
static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static char *
|
||||
getlogin_basic(int *status)
|
||||
{
|
||||
static char logname[MAXLOGNAME];
|
||||
|
||||
if (_logname_valid == 0) {
|
||||
if (_getlogin(logname, sizeof(logname)) < 0) {
|
||||
*status = errno;
|
||||
return (NULL);
|
||||
}
|
||||
_logname_valid = 1;
|
||||
}
|
||||
*status = 0;
|
||||
return (*logname ? logname : NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
getlogin(void)
|
||||
{
|
||||
char *result;
|
||||
int status;
|
||||
static char logname[MAXLOGNAME];
|
||||
|
||||
THREAD_LOCK();
|
||||
result = getlogin_basic(&status);
|
||||
THREAD_UNLOCK();
|
||||
return (result);
|
||||
if (_getlogin(logname, sizeof(logname)) < 0)
|
||||
return (NULL);
|
||||
return (logname[0] != '\0' ? logname : NULL);
|
||||
}
|
||||
|
||||
int
|
||||
getlogin_r(char *logname, int namelen)
|
||||
{
|
||||
char *result;
|
||||
char tmpname[MAXLOGNAME];
|
||||
int len;
|
||||
int status;
|
||||
|
||||
if (namelen < 1)
|
||||
return (ERANGE);
|
||||
logname[0] = '\0';
|
||||
|
||||
THREAD_LOCK();
|
||||
result = getlogin_basic(&status);
|
||||
if (status == 0 && result != NULL) {
|
||||
len = strlen(result) + 1;
|
||||
if (len > namelen)
|
||||
status = ERANGE;
|
||||
else
|
||||
strncpy(logname, result, len);
|
||||
}
|
||||
THREAD_UNLOCK();
|
||||
return (status);
|
||||
if (_getlogin(tmpname, sizeof(tmpname)) < 0)
|
||||
return (errno);
|
||||
len = strlen(tmpname) + 1;
|
||||
if (len > namelen)
|
||||
return (ERANGE);
|
||||
strlcpy(logname, tmpname, len);
|
||||
return (0);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ SRCS+= i386_get_fsbase.c i386_get_gsbase.c i386_get_ioperm.c i386_get_ldt.c \
|
||||
i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c
|
||||
|
||||
MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S \
|
||||
sbrk.S setlogin.S syscall.S
|
||||
sbrk.S syscall.S
|
||||
|
||||
NOASM+= vfork.o
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)setlogin.s 5.2 (Berkeley) 4/12/91"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <machine/asm.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl CNAME(_logname_valid) /* in _getlogin() */
|
||||
|
||||
SYSCALL(setlogin)
|
||||
PIC_PROLOGUE
|
||||
movl $0,PIC_GOTOFF(CNAME(_logname_valid))
|
||||
PIC_EPILOGUE
|
||||
ret /* setlogin(name) */
|
||||
END(__sys_setlogin)
|
||||
|
||||
.section .note.GNU-stack,"",%progbits
|
@ -1,3 +1,3 @@
|
||||
# $FreeBSD$
|
||||
|
||||
MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S
|
||||
MDASM+= brk.S cerror.S exect.S sbrk.S
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Peter Grehan.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* $NetBSD: setlogin.S,v 1.3 1998/11/24 11:14:57 tsubai Exp $ */
|
||||
|
||||
#include <machine/asm.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl CNAME(_logname_valid) /* in _getlogin() */
|
||||
|
||||
SYSCALL(setlogin)
|
||||
#ifdef PIC
|
||||
mflr %r10
|
||||
bl _GLOBAL_OFFSET_TABLE_@local-4
|
||||
mflr %r4
|
||||
lwz %r4,CNAME(_logname_valid)@got(%r4)
|
||||
li %r5,%r0
|
||||
stw %r5,0(%r4)
|
||||
mtlr %r10
|
||||
#else
|
||||
lis %r4,CNAME(_logname_valid)@ha
|
||||
li %r5,0
|
||||
stw %r5,CNAME(_logname_valid)@l(%r4)
|
||||
#endif
|
||||
blr
|
||||
|
||||
.section .note.GNU-stack,"",%progbits
|
@ -1,3 +1,3 @@
|
||||
# $FreeBSD$
|
||||
|
||||
MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S
|
||||
MDASM+= brk.S cerror.S exect.S sbrk.S
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Peter Grehan.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* $NetBSD: setlogin.S,v 1.3 1998/11/24 11:14:57 tsubai Exp $ */
|
||||
|
||||
#include <machine/asm.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl CNAME(_logname_valid) /* in _getlogin() */
|
||||
|
||||
SYSCALL(setlogin)
|
||||
addis %r4,%r2,CNAME(_logname_valid)@toc@ha
|
||||
li %r5,0
|
||||
stw %r5,CNAME(_logname_valid)@toc@l(%r4)
|
||||
blr
|
||||
|
||||
.section .note.GNU-stack,"",%progbits
|
@ -12,4 +12,4 @@ SRCS+= __sparc_sigtramp_setup.c \
|
||||
|
||||
CFLAGS+= -I${LIBC_SRCTOP}/sparc64/fpu
|
||||
|
||||
MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S sigaction1.S
|
||||
MDASM+= brk.S cerror.S exect.S sbrk.S sigaction1.S
|
||||
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This software was developed by the Computer Systems Engineering group
|
||||
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
||||
* contributed to Berkeley.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: Header: setlogin.s,v 1.1 91/07/06 13:06:00 torek Exp
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)setlogin.s 8.1 (Berkeley) 6/4/93"
|
||||
#if 0
|
||||
RCSID("$NetBSD: setlogin.S,v 1.3 2000/07/21 03:14:15 eeh Exp $")
|
||||
#endif
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
#include <machine/asm.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl CNAME(_logname_valid) /* in _getlogin() */
|
||||
|
||||
_SYSENTRY(setlogin)
|
||||
_SYSCALL(setlogin)
|
||||
PIC_PROLOGUE(%o3, %o2)
|
||||
SET(CNAME(_logname_valid), %o2, %o3)
|
||||
retl
|
||||
stw %g0, [%o3]
|
||||
_SYSEND(setlogin)
|
Loading…
Reference in New Issue
Block a user