|
|
0034f4 |
From 181d6fb901afa5aa2e87c4e5f5de4a0b77a1cac5 Mon Sep 17 00:00:00 2001
|
|
|
0034f4 |
From: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
0034f4 |
Date: Mon, 29 Aug 2022 17:44:09 +0200
|
|
|
0034f4 |
Subject: [PATCH] CLIENT: fix thread unsafe acces to get*ent structs.
|
|
|
0034f4 |
MIME-Version: 1.0
|
|
|
0034f4 |
Content-Type: text/plain; charset=UTF-8
|
|
|
0034f4 |
Content-Transfer-Encoding: 8bit
|
|
|
0034f4 |
|
|
|
0034f4 |
All get*ent structs were protected with socket mutex. In case SSSD
|
|
|
0034f4 |
is built with lock-free client support, `sss_nss_lock()` is a no-op,
|
|
|
0034f4 |
thus resulting in thread unsafe access.
|
|
|
0034f4 |
|
|
|
0034f4 |
This patch changes those structs to have thread local storage.
|
|
|
0034f4 |
|
|
|
0034f4 |
This conradicts following note in the man page:
|
|
|
0034f4 |
```
|
|
|
0034f4 |
The function getgrent_r() is not really reentrant since it shares
|
|
|
0034f4 |
the reading position in the stream with all other threads.
|
|
|
0034f4 |
```
|
|
|
0034f4 |
I'm not sure if 3rd party apps can legally assume this behaviour
|
|
|
0034f4 |
based on a note in a man page. And in some cases, non-sharing reading
|
|
|
0034f4 |
position between threads might make more sense.
|
|
|
0034f4 |
But that way or another, this is better than thread unsafe access.
|
|
|
0034f4 |
|
|
|
0034f4 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
0034f4 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
0034f4 |
(cherry picked from commit 69fd828c1d5e92bc3b2e327a45dfed116f49d50a)
|
|
|
0034f4 |
---
|
|
|
0034f4 |
src/sss_client/nss_group.c | 14 ++++++++++++--
|
|
|
0034f4 |
src/sss_client/nss_hosts.c | 8 +++++++-
|
|
|
0034f4 |
src/sss_client/nss_ipnetworks.c | 8 +++++++-
|
|
|
0034f4 |
src/sss_client/nss_passwd.c | 8 +++++++-
|
|
|
0034f4 |
src/sss_client/nss_services.c | 8 +++++++-
|
|
|
0034f4 |
5 files changed, 40 insertions(+), 6 deletions(-)
|
|
|
0034f4 |
|
|
|
0034f4 |
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c
|
|
|
0034f4 |
index f102711ec..fcabf8cfc 100644
|
|
|
0034f4 |
--- a/src/sss_client/nss_group.c
|
|
|
0034f4 |
+++ b/src/sss_client/nss_group.c
|
|
|
0034f4 |
@@ -19,6 +19,8 @@
|
|
|
0034f4 |
|
|
|
0034f4 |
/* GROUP database NSS interface */
|
|
|
0034f4 |
|
|
|
0034f4 |
+#include "config.h"
|
|
|
0034f4 |
+
|
|
|
0034f4 |
#include <nss.h>
|
|
|
0034f4 |
#include <errno.h>
|
|
|
0034f4 |
#include <sys/types.h>
|
|
|
0034f4 |
@@ -31,7 +33,11 @@
|
|
|
0034f4 |
#include "nss_mc.h"
|
|
|
0034f4 |
#include "nss_common.h"
|
|
|
0034f4 |
|
|
|
0034f4 |
-static struct sss_nss_getgrent_data {
|
|
|
0034f4 |
+static
|
|
|
0034f4 |
+#ifdef HAVE_PTHREAD_EXT
|
|
|
0034f4 |
+__thread
|
|
|
0034f4 |
+#endif
|
|
|
0034f4 |
+struct sss_nss_getgrent_data {
|
|
|
0034f4 |
size_t len;
|
|
|
0034f4 |
size_t ptr;
|
|
|
0034f4 |
uint8_t *data;
|
|
|
0034f4 |
@@ -53,7 +59,11 @@ enum sss_nss_gr_type {
|
|
|
0034f4 |
GETGR_GID
|
|
|
0034f4 |
};
|
|
|
0034f4 |
|
|
|
0034f4 |
-static struct sss_nss_getgr_data {
|
|
|
0034f4 |
+static
|
|
|
0034f4 |
+#ifdef HAVE_PTHREAD_EXT
|
|
|
0034f4 |
+__thread
|
|
|
0034f4 |
+#endif
|
|
|
0034f4 |
+struct sss_nss_getgr_data {
|
|
|
0034f4 |
enum sss_nss_gr_type type;
|
|
|
0034f4 |
union {
|
|
|
0034f4 |
char *grname;
|
|
|
0034f4 |
diff --git a/src/sss_client/nss_hosts.c b/src/sss_client/nss_hosts.c
|
|
|
0034f4 |
index 59fe82e59..81017bc9d 100644
|
|
|
0034f4 |
--- a/src/sss_client/nss_hosts.c
|
|
|
0034f4 |
+++ b/src/sss_client/nss_hosts.c
|
|
|
0034f4 |
@@ -20,6 +20,8 @@
|
|
|
0034f4 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
0034f4 |
*/
|
|
|
0034f4 |
|
|
|
0034f4 |
+#include "config.h"
|
|
|
0034f4 |
+
|
|
|
0034f4 |
#include <nss.h>
|
|
|
0034f4 |
#include <netdb.h>
|
|
|
0034f4 |
#include <resolv.h>
|
|
|
0034f4 |
@@ -33,7 +35,11 @@
|
|
|
0034f4 |
#include <string.h>
|
|
|
0034f4 |
#include "sss_cli.h"
|
|
|
0034f4 |
|
|
|
0034f4 |
-static struct sss_nss_gethostent_data {
|
|
|
0034f4 |
+static
|
|
|
0034f4 |
+#ifdef HAVE_PTHREAD_EXT
|
|
|
0034f4 |
+__thread
|
|
|
0034f4 |
+#endif
|
|
|
0034f4 |
+struct sss_nss_gethostent_data {
|
|
|
0034f4 |
size_t len;
|
|
|
0034f4 |
size_t ptr;
|
|
|
0034f4 |
uint8_t *data;
|
|
|
0034f4 |
diff --git a/src/sss_client/nss_ipnetworks.c b/src/sss_client/nss_ipnetworks.c
|
|
|
0034f4 |
index 93d564496..85d9cc746 100644
|
|
|
0034f4 |
--- a/src/sss_client/nss_ipnetworks.c
|
|
|
0034f4 |
+++ b/src/sss_client/nss_ipnetworks.c
|
|
|
0034f4 |
@@ -20,6 +20,8 @@
|
|
|
0034f4 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
0034f4 |
*/
|
|
|
0034f4 |
|
|
|
0034f4 |
+#include "config.h"
|
|
|
0034f4 |
+
|
|
|
0034f4 |
#include <nss.h>
|
|
|
0034f4 |
#include <netdb.h>
|
|
|
0034f4 |
#include <resolv.h>
|
|
|
0034f4 |
@@ -33,7 +35,11 @@
|
|
|
0034f4 |
#include <string.h>
|
|
|
0034f4 |
#include "sss_cli.h"
|
|
|
0034f4 |
|
|
|
0034f4 |
-static struct sss_nss_getnetent_data {
|
|
|
0034f4 |
+static
|
|
|
0034f4 |
+#ifdef HAVE_PTHREAD_EXT
|
|
|
0034f4 |
+__thread
|
|
|
0034f4 |
+#endif
|
|
|
0034f4 |
+struct sss_nss_getnetent_data {
|
|
|
0034f4 |
size_t len;
|
|
|
0034f4 |
size_t ptr;
|
|
|
0034f4 |
uint8_t *data;
|
|
|
0034f4 |
diff --git a/src/sss_client/nss_passwd.c b/src/sss_client/nss_passwd.c
|
|
|
0034f4 |
index c386dd370..ec19908f7 100644
|
|
|
0034f4 |
--- a/src/sss_client/nss_passwd.c
|
|
|
0034f4 |
+++ b/src/sss_client/nss_passwd.c
|
|
|
0034f4 |
@@ -19,6 +19,8 @@
|
|
|
0034f4 |
|
|
|
0034f4 |
/* PASSWD database NSS interface */
|
|
|
0034f4 |
|
|
|
0034f4 |
+#include "config.h"
|
|
|
0034f4 |
+
|
|
|
0034f4 |
#include <nss.h>
|
|
|
0034f4 |
#include <errno.h>
|
|
|
0034f4 |
#include <sys/types.h>
|
|
|
0034f4 |
@@ -30,7 +32,11 @@
|
|
|
0034f4 |
#include "nss_mc.h"
|
|
|
0034f4 |
#include "nss_common.h"
|
|
|
0034f4 |
|
|
|
0034f4 |
-static struct sss_nss_getpwent_data {
|
|
|
0034f4 |
+static
|
|
|
0034f4 |
+#ifdef HAVE_PTHREAD_EXT
|
|
|
0034f4 |
+__thread
|
|
|
0034f4 |
+#endif
|
|
|
0034f4 |
+struct sss_nss_getpwent_data {
|
|
|
0034f4 |
size_t len;
|
|
|
0034f4 |
size_t ptr;
|
|
|
0034f4 |
uint8_t *data;
|
|
|
0034f4 |
diff --git a/src/sss_client/nss_services.c b/src/sss_client/nss_services.c
|
|
|
0034f4 |
index f8c2092cb..4f44cb29c 100644
|
|
|
0034f4 |
--- a/src/sss_client/nss_services.c
|
|
|
0034f4 |
+++ b/src/sss_client/nss_services.c
|
|
|
0034f4 |
@@ -20,6 +20,8 @@
|
|
|
0034f4 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
0034f4 |
*/
|
|
|
0034f4 |
|
|
|
0034f4 |
+#include "config.h"
|
|
|
0034f4 |
+
|
|
|
0034f4 |
#include <nss.h>
|
|
|
0034f4 |
#include <netdb.h>
|
|
|
0034f4 |
#include <errno.h>
|
|
|
0034f4 |
@@ -31,7 +33,11 @@
|
|
|
0034f4 |
#include <string.h>
|
|
|
0034f4 |
#include "sss_cli.h"
|
|
|
0034f4 |
|
|
|
0034f4 |
-static struct sss_nss_getservent_data {
|
|
|
0034f4 |
+static
|
|
|
0034f4 |
+#ifdef HAVE_PTHREAD_EXT
|
|
|
0034f4 |
+__thread
|
|
|
0034f4 |
+#endif
|
|
|
0034f4 |
+struct sss_nss_getservent_data {
|
|
|
0034f4 |
size_t len;
|
|
|
0034f4 |
size_t ptr;
|
|
|
0034f4 |
uint8_t *data;
|
|
|
0034f4 |
--
|
|
|
0034f4 |
2.37.3
|
|
|
0034f4 |
|