mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 05:13:07 +00:00
Merge pull request #3972 from mjstapp/fix_privs_race
libs: fix race in privs changes
This commit is contained in:
commit
6e0d7d0dbb
41
lib/privs.c
41
lib/privs.c
@ -708,19 +708,19 @@ struct zebra_privs_t *_zprivs_raise(struct zebra_privs_t *privs,
|
|||||||
|
|
||||||
/* If we're already elevated, just return */
|
/* If we're already elevated, just return */
|
||||||
pthread_mutex_lock(&(privs->mutex));
|
pthread_mutex_lock(&(privs->mutex));
|
||||||
if (++privs->refcount > 1) {
|
{
|
||||||
pthread_mutex_unlock(&(privs->mutex));
|
if (++(privs->refcount) == 1) {
|
||||||
return privs;
|
errno = 0;
|
||||||
|
if (privs->change(ZPRIVS_RAISE)) {
|
||||||
|
zlog_err("%s: Failed to raise privileges (%s)",
|
||||||
|
funcname, safe_strerror(errno));
|
||||||
|
}
|
||||||
|
errno = save_errno;
|
||||||
|
privs->raised_in_funcname = funcname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&(privs->mutex));
|
pthread_mutex_unlock(&(privs->mutex));
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
if (privs->change(ZPRIVS_RAISE)) {
|
|
||||||
zlog_err("%s: Failed to raise privileges (%s)",
|
|
||||||
funcname, safe_strerror(errno));
|
|
||||||
}
|
|
||||||
errno = save_errno;
|
|
||||||
privs->raised_in_funcname = funcname;
|
|
||||||
return privs;
|
return privs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -733,19 +733,20 @@ void _zprivs_lower(struct zebra_privs_t **privs)
|
|||||||
|
|
||||||
/* Don't lower privs if there's another caller */
|
/* Don't lower privs if there's another caller */
|
||||||
pthread_mutex_lock(&(*privs)->mutex);
|
pthread_mutex_lock(&(*privs)->mutex);
|
||||||
if (--((*privs)->refcount) > 0) {
|
{
|
||||||
pthread_mutex_unlock(&(*privs)->mutex);
|
if (--((*privs)->refcount) == 0) {
|
||||||
return;
|
errno = 0;
|
||||||
|
if ((*privs)->change(ZPRIVS_LOWER)) {
|
||||||
|
zlog_err("%s: Failed to lower privileges (%s)",
|
||||||
|
(*privs)->raised_in_funcname,
|
||||||
|
safe_strerror(errno));
|
||||||
|
}
|
||||||
|
errno = save_errno;
|
||||||
|
(*privs)->raised_in_funcname = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&(*privs)->mutex);
|
pthread_mutex_unlock(&(*privs)->mutex);
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
if ((*privs)->change(ZPRIVS_LOWER)) {
|
|
||||||
zlog_err("%s: Failed to lower privileges (%s)",
|
|
||||||
(*privs)->raised_in_funcname, safe_strerror(errno));
|
|
||||||
}
|
|
||||||
errno = save_errno;
|
|
||||||
(*privs)->raised_in_funcname = NULL;
|
|
||||||
*privs = NULL;
|
*privs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user