155c9421b9
There are several issues with getpass(3). Many implementations of it share the same issues that the infamous gets(3). In glibc it's not so terrible, since it's a wrapper around getline(3). But it still has an important bug: If the password is long enough, getline(3) will realloc(3) memory, and prefixes of the password will be laying around in some deallocated memory. See the getpass(3) manual page for more details, and especially the commit that marked it as deprecated, which links to a long discussion in the linux-man@ mailing list. So, readpassphrase(3bsd) is preferrable, which is provided by libbsd on GNU systems. However, using readpassphrase(3) directly is a bit verbose, so we can write our own wrapper with a simpler interface similar to that of getpass(3). One of the benefits of writing our own interface around readpassphrase(3) is that we can hide there any checks that should be done always and which would be error-prone to repeat every time. For example, check that there was no truncation in the password. Also, use malloc(3) to get the buffer, instead of using a global buffer. We're not using a multithreaded program (and it wouldn't make sense to do so), but it's nice to know that the visibility of our passwords is as limited as possible. erase_pass() is a clean-up function that handles all clean-up correctly, including zeroing the entire buffer, and then free(3)ing the memory. By using [[gnu::malloc(erase_pass)]], we make sure that we don't leak the buffers in any case, since the compiler will be able to enforce clean up. Link: <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit?id=7ca189099d73bde954eed2d7fc21732bcc8ddc6b> Reported-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org> |
||
---|---|---|
.. | ||
.indent.pro | ||
commonio.c | ||
commonio.h | ||
defines.h | ||
encrypt.c | ||
exitcodes.h | ||
faillog.h | ||
fields.c | ||
fputsx.c | ||
get_gid.c | ||
get_pid.c | ||
get_uid.c | ||
getdef.c | ||
getdef.h | ||
getlong.c | ||
getulong.c | ||
groupio.c | ||
groupio.h | ||
groupmem.c | ||
gshadow_.h | ||
gshadow.c | ||
lockpw.c | ||
Makefile.am | ||
nscd.c | ||
nscd.h | ||
nss.c | ||
pam_defs.h | ||
port.c | ||
port.h | ||
prototypes.h | ||
pwauth.c | ||
pwauth.h | ||
pwio.c | ||
pwio.h | ||
pwmem.c | ||
run_part.c | ||
run_part.h | ||
selinux.c | ||
semanage.c | ||
sgetgrent.c | ||
sgetpwent.c | ||
sgetspent.c | ||
sgroupio.c | ||
sgroupio.h | ||
shadow.c | ||
shadowio.c | ||
shadowio.h | ||
shadowlog_internal.h | ||
shadowlog.c | ||
shadowlog.h | ||
shadowmem.c | ||
spawn.c | ||
sssd.c | ||
sssd.h | ||
subordinateio.c | ||
subordinateio.h | ||
tcbfuncs.c | ||
tcbfuncs.h | ||
utent.c |