From 153264bd31a45b88622672b1c7f00455136cf471 Mon Sep 17 00:00:00 2001 From: Richard Kojedzinszky Date: Wed, 17 Jan 2024 20:48:02 +0100 Subject: [PATCH] libzfs: make userquota_propname_decode threadsafe Reviewed-by: Brian Behlendorf Reviewed-by: Tino Reichardt Signed-off-by: Richard Kojedzinszky Closes #15793 --- lib/libzfs/libzfs_dataset.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index f6403c990bef..0fd3fe26cb12 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -66,6 +66,10 @@ #include "libzfs_impl.h" #include "zfs_deleg.h" +static __thread struct passwd gpwd; +static __thread struct group ggrp; +static __thread char rpbuf[2048]; + static int userquota_propname_decode(const char *propname, boolean_t zoned, zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp); @@ -3208,11 +3212,15 @@ userquota_propname_decode(const char *propname, boolean_t zoned, cp = strchr(propname, '@') + 1; - if (isuser && (pw = getpwnam(cp)) != NULL) { + if (isuser && + getpwnam_r(cp, &gpwd, rpbuf, sizeof (rpbuf), &pw) == 0 && + pw != NULL) { if (zoned && getzoneid() == GLOBAL_ZONEID) return (ENOENT); *ridp = pw->pw_uid; - } else if (isgroup && (gr = getgrnam(cp)) != NULL) { + } else if (isgroup && + getgrnam_r(cp, &ggrp, rpbuf, sizeof (rpbuf), &gr) == 0 && + gr != NULL) { if (zoned && getzoneid() == GLOBAL_ZONEID) return (ENOENT); *ridp = gr->gr_gid;