libselinux: use dummy variable to silence glibc 2.34 warnings
PATCH 1/1 libselinux: use dummy variable to silence glibc 2.34 warnings
Glibc 2.34 added an access function attribute to pthread_setspecific(3). This leads to the following GCC warnings:
In file included from matchpathcon.c:5:
matchpathcon.c: In function ‘matchpathcon_init_prefix’:
selinux_internal.h:38:25: error: ‘pthread_setspecific’ expecting 1 byte in a region of size 0 [-Werror=stringop-overread]
38 | pthread_setspecific(KEY, VALUE); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matchpathcon.c:359:9: note: in expansion of macro ‘__selinux_setspecific’
359 | __selinux_setspecific(destructor_key, (void *)1);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from selinux_internal.h:2,
from matchpathcon.c:5:
/usr/include/pthread.h:1167:12: note: in a call to function ‘pthread_setspecific’ declared with attribute ‘access (none, 2)’
1167 | extern int pthread_setspecific (pthread_key_t __key,
| ^~~~~~~~~~~~~~~~~~~
The actual value and the validity of the passed pointer is irrelevant, since it does not gets accessed internally by glibc and pthread_getspecific(3) is not used.
Use a pointer to a (temporary) valid object to please GCC.
--- libselinux/src/matchpathcon.c | 4 +++- libselinux/src/procattr.c | 4 +++- libselinux/src/setrans_client.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)
libselinux/src/matchpathcon.c +3 -1
@@ -352,11 +352,13 @@ static void matchpathcon_init_once(void)int matchpathcon_init_prefix (const char *path,const char *subset) { +int dummy; +if (!mycanoncon) mycanoncon = default_canoncon;__selinux_once (once, matchpathcon_init_once); -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key, &dummy); options[SELABEL_OPT_SUBSET ].type =SELABEL_OPT_SUBSET ; options[SELABEL_OPT_SUBSET ].value = subset;
libselinux/src/procattr.c +3 -1
@@ -68,7 +68,9 @@ void __attribute__((destructor)) procattr_destructor(void)static inline void init_thread_destructor (void ) {if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +int dummy; + +__selinux_setspecific (destructor_key, &dummy); destructor_initialized =1 ; } }
libselinux/src/setrans_client.c +3 -1
@@ -272,7 +272,9 @@ static inline void init_thread_destructor(void)if (!has_setrans)return ;if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +int dummy; + +__selinux_setspecific (destructor_key, &dummy); destructor_initialized =1 ; } }
Signature · 1 line
2.33.0
Quoted 81 lines · Christian Göttsche
Glibc 2.34 added an access function attribute to
pthread_setspecific(3). This leads to the following GCC warnings:In file included from matchpathcon.c:5:
matchpathcon.c: In function ‘matchpathcon_init_prefix’:
selinux_internal.h:38:25: error: ‘pthread_setspecific’ expecting 1 byte in a region of size 0 [-Werror=stringop-overread]
38 |pthread_setspecific(KEY, VALUE); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matchpathcon.c:359:9: note: in expansion of macro ‘__selinux_setspecific’
359 |__selinux_setspecific(destructor_key, (void *)1);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from selinux_internal.h:2,
from matchpathcon.c:5:
/usr/include/pthread.h:1167:12: note: in a call to function ‘pthread_setspecific’ declared with attribute ‘access (none, 2)’
1167 | extern intpthread_setspecific(pthread_key_t__key,
| ^~~~~~~~~~~~~~~~~~~The actual value and the validity of the passed pointer is irrelevant, since it does not gets accessed internally by glibc and
pthread_getspecific(3)is not used.
Use a pointer to a (temporary) valid object to please GCC.Signed-off-by Christian Göttsche <[email protected]>--- libselinux/src/matchpathcon.c | 4 +++- libselinux/src/procattr.c | 4 +++- libselinux/src/setrans_client.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)libselinux/src/matchpathcon.c +3
-1@@ -352,11 +352,13 @@ static void matchpathcon_init_once(void)int matchpathcon_init_prefix (const char *path,const char *subset) { +int dummy; +if (!mycanoncon) mycanoncon = default_canoncon;__selinux_once (once, matchpathcon_init_once); -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key, &dummy); options[SELABEL_OPT_SUBSET ].type =SELABEL_OPT_SUBSET ; options[SELABEL_OPT_SUBSET ].value = subset;libselinux/src/procattr.c +3
-1@@ -68,7 +68,9 @@ void __attribute__((destructor)) procattr_destructor(void)static inline void init_thread_destructor (void ) {if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +int dummy; + +__selinux_setspecific (destructor_key, &dummy); destructor_initialized =1 ; } }libselinux/src/setrans_client.c +3
-2@@ -272,7 +272,9 @@ static inline void init_thread_destructor(void)if (!has_setrans)return ;if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +int dummy; + +__selinux_setspecific (destructor_key, &dummy); destructor_initialized =1 ; } } --
Quoted 2 lines
2.33.0
Hello,
Thanks for working on this. While this patch fixes the precise warning, I fear that future improvements on the analysis performed by compilers (or by static analysis tools) will lead to future warnings, as we are still abusing the pthread_setspecific interface after your
patch: "dummy" is not initialized (so a tool could report a "use of uninitialized variable"), and is destroyed after the scope of the functions (so a tool could report a "use after free" or a "use of a stack pointer beyond its scope").
These issues can be fixed by making dummy "static char dummy;" for example. What do you think?
Thanks,
Nicolas
Quoted 97 lines · Nicolas Iooss
Quoted 81 lines · Christian Göttsche
Glibc 2.34 added an access function attribute to
pthread_setspecific(3). This leads to the following GCC warnings:In file included from matchpathcon.c:5:
matchpathcon.c: In function ‘matchpathcon_init_prefix’:
selinux_internal.h:38:25: error: ‘pthread_setspecific’ expecting 1 byte in a region of size 0 [-Werror=stringop-overread]
38 |pthread_setspecific(KEY, VALUE); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matchpathcon.c:359:9: note: in expansion of macro ‘__selinux_setspecific’
359 |__selinux_setspecific(destructor_key, (void *)1);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from selinux_internal.h:2,
from matchpathcon.c:5:
/usr/include/pthread.h:1167:12: note: in a call to function ‘pthread_setspecific’ declared with attribute ‘access (none, 2)’
1167 | extern intpthread_setspecific(pthread_key_t__key,
| ^~~~~~~~~~~~~~~~~~~The actual value and the validity of the passed pointer is irrelevant, since it does not gets accessed internally by glibc and
pthread_getspecific(3)is not used.
Use a pointer to a (temporary) valid object to please GCC.Signed-off-by Christian Göttsche <[email protected]>--- libselinux/src/matchpathcon.c | 4 +++- libselinux/src/procattr.c | 4 +++- libselinux/src/setrans_client.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)libselinux/src/matchpathcon.c +3
-1@@ -352,11 +352,13 @@ static void matchpathcon_init_once(void)int matchpathcon_init_prefix (const char *path,const char *subset) { +int dummy; +if (!mycanoncon) mycanoncon = default_canoncon;__selinux_once (once, matchpathcon_init_once); -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key, &dummy); options[SELABEL_OPT_SUBSET ].type =SELABEL_OPT_SUBSET ; options[SELABEL_OPT_SUBSET ].value = subset;libselinux/src/procattr.c +3
-1@@ -68,7 +68,9 @@ void __attribute__((destructor)) procattr_destructor(void)static inline void init_thread_destructor (void ) {if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +int dummy; + +__selinux_setspecific (destructor_key, &dummy); destructor_initialized =1 ; } }libselinux/src/setrans_client.c +3
-2@@ -272,7 +272,9 @@ static inline void init_thread_destructor(void)if (!has_setrans)return ;if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +int dummy; + +__selinux_setspecific (destructor_key, &dummy); destructor_initialized =1 ; } } --Quoted 2 lines
2.33.0
Hello,
Thanks for working on this. While this patch fixes the precise warning, I fear that future improvements on the analysis performed by compilers (or by static analysis tools) will lead to future warnings, as we are still abusing thepthread_setspecificinterface after your
patch: "dummy" is not initialized (so a tool could report a "use of uninitialized variable"), and is destroyed after the scope of the functions (so a tool could report a "use after free" or a "use of a stack pointer beyond its scope").
Quoted 3 lines
These issues can be fixed by making dummy "static char dummy;" for example. What do you think?
I don't quite like introducing 3 static variables, although their footprint is probably negligible.
What about using the address of a global variable, e.g.:
__selinux_setspecific(destructor_key, /* use some valid address to please GCC */ &selinux_mnt);
Quoted 3 lines
Thanks,
Nicolas
PATCH v2 1/1 libselinux: use valid address to silence glibc 2.34 warnings
In reply to Christian GöttscheGlibc 2.34 added an access function attribute to pthread_setspecific(3). This leads to the following GCC warnings:
In file included from matchpathcon.c:5:
matchpathcon.c: In function ‘matchpathcon_init_prefix’:
selinux_internal.h:38:25: error: ‘pthread_setspecific’ expecting 1 byte in a region of size 0 [-Werror=stringop-overread]
38 | pthread_setspecific(KEY, VALUE); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matchpathcon.c:359:9: note: in expansion of macro ‘__selinux_setspecific’
359 | __selinux_setspecific(destructor_key, (void *)1);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from selinux_internal.h:2,
from matchpathcon.c:5:
/usr/include/pthread.h:1167:12: note: in a call to function ‘pthread_setspecific’ declared with attribute ‘access (none, 2)’
1167 | extern int pthread_setspecific (pthread_key_t __key,
| ^~~~~~~~~~~~~~~~~~~
The actual value and the validity of the passed pointer is irrelevant, since it does not gets accessed internally by glibc and pthread_getspecific(3) is not used.
Use a pointer to a global object to please GCC.
--- libselinux/src/matchpathcon.c | 2 +- libselinux/src/procattr.c | 2 +- libselinux/src/setrans_client.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
libselinux/src/matchpathcon.c +1 -1
@@ -356,7 +356,7 @@ int matchpathcon_init_prefix(const char *path, const char *subset) mycanoncon = default_canoncon;__selinux_once (once, matchpathcon_init_once); -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); options[SELABEL_OPT_SUBSET ].type =SELABEL_OPT_SUBSET ; options[SELABEL_OPT_SUBSET ].value = subset;
libselinux/src/procattr.c +1 -1
@@ -68,7 +68,7 @@ void __attribute__((destructor)) procattr_destructor(void)static inline void init_thread_destructor (void ) {if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); destructor_initialized =1 ; } }
libselinux/src/setrans_client.c +1 -1
@@ -272,7 +272,7 @@ static inline void init_thread_destructor(void)if (!has_setrans)return ;if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); destructor_initialized =1 ; } }
Signature · 1 line
2.33.0
Re: [PATCH v2] libselinux: use valid address to silence glibc 2.34 warnings
Quoted 18 lines · Christian Göttsche
Glibc 2.34 added an access function attribute to
pthread_setspecific(3). This leads to the following GCC warnings:In file included from matchpathcon.c:5:
matchpathcon.c: In function ‘matchpathcon_init_prefix’:
selinux_internal.h:38:25: error: ‘pthread_setspecific’ expecting 1 byte in a region of size 0 [-Werror=stringop-overread]
38 |pthread_setspecific(KEY, VALUE); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matchpathcon.c:359:9: note: in expansion of macro ‘__selinux_setspecific’
359 |__selinux_setspecific(destructor_key, (void *)1);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from selinux_internal.h:2,
from matchpathcon.c:5:
/usr/include/pthread.h:1167:12: note: in a call to function ‘pthread_setspecific’ declared with attribute ‘access (none, 2)’
1167 | extern intpthread_setspecific(pthread_key_t__key,
| ^~~~~~~~~~~~~~~~~~~
Quoted 7 lines
The actual value and the validity of the passed pointer is irrelevant, since it does not gets accessed internally by glibc and
pthread_getspecific(3)is not used.
Use a pointer to a global object to please GCC.
Sorry for the delay, I have been busy with other topics.
Thanks!
Nicolas
Quoted 48 lines
--- libselinux/src/matchpathcon.c | 2 +- libselinux/src/procattr.c | 2 +- libselinux/src/setrans_client.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)libselinux/src/matchpathcon.c +1
-1@@ -356,7 +356,7 @@ int matchpathcon_init_prefix(const char *path, const char *subset) mycanoncon = default_canoncon;__selinux_once (once, matchpathcon_init_once); -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); options[SELABEL_OPT_SUBSET ].type =SELABEL_OPT_SUBSET ; options[SELABEL_OPT_SUBSET ].value = subset;libselinux/src/procattr.c +1
-1@@ -68,7 +68,7 @@ void __attribute__((destructor)) procattr_destructor(void)static inline void init_thread_destructor (void ) {if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); destructor_initialized =1 ; } }libselinux/src/setrans_client.c +1
-2@@ -272,7 +272,7 @@ static inline void init_thread_destructor(void)if (!has_setrans)return ;if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); destructor_initialized =1 ; } } --2.33.0
Re: [PATCH v2] libselinux: use valid address to silence glibc 2.34 warnings
Quoted 29 lines · Nicolas Iooss
Quoted 18 lines · Christian Göttsche
Glibc 2.34 added an access function attribute to
pthread_setspecific(3). This leads to the following GCC warnings:In file included from matchpathcon.c:5:
matchpathcon.c: In function ‘matchpathcon_init_prefix’:
selinux_internal.h:38:25: error: ‘pthread_setspecific’ expecting 1 byte in a region of size 0 [-Werror=stringop-overread]
38 |pthread_setspecific(KEY, VALUE); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matchpathcon.c:359:9: note: in expansion of macro ‘__selinux_setspecific’
359 |__selinux_setspecific(destructor_key, (void *)1);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from selinux_internal.h:2,
from matchpathcon.c:5:
/usr/include/pthread.h:1167:12: note: in a call to function ‘pthread_setspecific’ declared with attribute ‘access (none, 2)’
1167 | extern intpthread_setspecific(pthread_key_t__key,
| ^~~~~~~~~~~~~~~~~~~Quoted 7 lines
The actual value and the validity of the passed pointer is irrelevant, since it does not gets accessed internally by glibc and
pthread_getspecific(3)is not used.
Use a pointer to a global object to please GCC.
Quoted 6 lines
Acked-by Nicolas Iooss <[email protected]>Sorry for the delay, I have been busy with other topics.
Thanks!
Nicolas
This patch is now applied.
Thanks!
Nicolas
Quoted 48 lines
Quoted 48 lines
--- libselinux/src/matchpathcon.c | 2 +- libselinux/src/procattr.c | 2 +- libselinux/src/setrans_client.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)libselinux/src/matchpathcon.c +1
-1@@ -356,7 +356,7 @@ int matchpathcon_init_prefix(const char *path, const char *subset) mycanoncon = default_canoncon;__selinux_once (once, matchpathcon_init_once); -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); options[SELABEL_OPT_SUBSET ].type =SELABEL_OPT_SUBSET ; options[SELABEL_OPT_SUBSET ].value = subset;libselinux/src/procattr.c +1
-1@@ -68,7 +68,7 @@ void __attribute__((destructor)) procattr_destructor(void)static inline void init_thread_destructor (void ) {if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); destructor_initialized =1 ; } }libselinux/src/setrans_client.c +1
-2@@ -272,7 +272,7 @@ static inline void init_thread_destructor(void)if (!has_setrans)return ;if (destructor_initialized ==0 ) { -__selinux_setspecific (destructor_key, (void *)1 ); +__selinux_setspecific (destructor_key,/* some valid address to please GCC */ &selinux_page_size); destructor_initialized =1 ; } } --2.33.0