signal: Use <sigsetops.h> for sigemptyset, sigfillset

Message ID 87eesglyc9.fsf@mid.deneb.enyo.de
State Committed
Headers
Series signal: Use <sigsetops.h> for sigemptyset, sigfillset |

Commit Message

Florian Weimer April 22, 2020, 8:27 a.m. UTC
  This avoids changing the entire sigset_t structure.  Updating the
actually used part is sufficient.

Tested on x86_64-linux-gnu and i686-linux-gnu.

-----
 signal/sigempty.c   | 7 +++----
 signal/sigfillset.c | 6 ++----
 2 files changed, 5 insertions(+), 8 deletions(-)
  

Comments

Andreas Schwab April 22, 2020, 8:37 a.m. UTC | #1
On Apr 22 2020, Florian Weimer wrote:

> This avoids changing the entire sigset_t structure.  Updating the
> actually used part is sufficient.

I'm not sure it's a good idea to leave most of the structure
uninitialized.

Andreas.
  
Florian Weimer April 22, 2020, 8:39 a.m. UTC | #2
* Andreas Schwab:

> On Apr 22 2020, Florian Weimer wrote:
>
>> This avoids changing the entire sigset_t structure.  Updating the
>> actually used part is sufficient.
>
> I'm not sure it's a good idea to leave most of the structure
> uninitialized.

Would you please elaborate?  How is this different from padding?
  
Andreas Schwab April 22, 2020, 9:40 a.m. UTC | #3
On Apr 22 2020, Florian Weimer wrote:

> * Andreas Schwab:
>
>> On Apr 22 2020, Florian Weimer wrote:
>>
>>> This avoids changing the entire sigset_t structure.  Updating the
>>> actually used part is sufficient.
>>
>> I'm not sure it's a good idea to leave most of the structure
>> uninitialized.
>
> Would you please elaborate?  How is this different from padding?

Padding is always unnamed.

Andreas.
  
Florian Weimer April 22, 2020, 9:44 a.m. UTC | #4
* Andreas Schwab:

> On Apr 22 2020, Florian Weimer wrote:
>
>> * Andreas Schwab:
>>
>>> On Apr 22 2020, Florian Weimer wrote:
>>>
>>>> This avoids changing the entire sigset_t structure.  Updating the
>>>> actually used part is sufficient.
>>>
>>> I'm not sure it's a good idea to leave most of the structure
>>> uninitialized.
>>
>> Would you please elaborate?  How is this different from padding?
>
> Padding is always unnamed.

Not if it is called __glibc_reserved.  I obviously meant named
padding.
  
Florian Weimer April 22, 2020, 10:02 a.m. UTC | #5
* Florian Weimer:

> * Andreas Schwab:
>
>> On Apr 22 2020, Florian Weimer wrote:
>>
>>> * Andreas Schwab:
>>>
>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>
>>>>> This avoids changing the entire sigset_t structure.  Updating the
>>>>> actually used part is sufficient.
>>>>
>>>> I'm not sure it's a good idea to leave most of the structure
>>>> uninitialized.
>>>
>>> Would you please elaborate?  How is this different from padding?
>>
>> Padding is always unnamed.
>
> Not if it is called __glibc_reserved.  I obviously meant named
> padding.

And sigprocmask has always left the padding uninitialized (even before
Adhemerval's changes).
  
Adhemerval Zanella Netto April 22, 2020, 11:47 a.m. UTC | #6
On 22/04/2020 07:02, Florian Weimer wrote:
> * Florian Weimer:
> 
>> * Andreas Schwab:
>>
>>> On Apr 22 2020, Florian Weimer wrote:
>>>
>>>> * Andreas Schwab:
>>>>
>>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>>
>>>>>> This avoids changing the entire sigset_t structure.  Updating the
>>>>>> actually used part is sufficient.
>>>>>
>>>>> I'm not sure it's a good idea to leave most of the structure
>>>>> uninitialized.
>>>>
>>>> Would you please elaborate?  How is this different from padding?
>>>
>>> Padding is always unnamed.
>>
>> Not if it is called __glibc_reserved.  I obviously meant named
>> padding.
> 
> And sigprocmask has always left the padding uninitialized (even before
> Adhemerval's changes).
> 

Should we change __sigemptyset/__sigfillset to fill the ununsed bits
instead?
  
Florian Weimer April 22, 2020, 12:14 p.m. UTC | #7
* Adhemerval Zanella via Libc-alpha:

> On 22/04/2020 07:02, Florian Weimer wrote:
>> * Florian Weimer:
>> 
>>> * Andreas Schwab:
>>>
>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>
>>>>> * Andreas Schwab:
>>>>>
>>>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>>>
>>>>>>> This avoids changing the entire sigset_t structure.  Updating the
>>>>>>> actually used part is sufficient.
>>>>>>
>>>>>> I'm not sure it's a good idea to leave most of the structure
>>>>>> uninitialized.
>>>>>
>>>>> Would you please elaborate?  How is this different from padding?
>>>>
>>>> Padding is always unnamed.
>>>
>>> Not if it is called __glibc_reserved.  I obviously meant named
>>> padding.
>> 
>> And sigprocmask has always left the padding uninitialized (even before
>> Adhemerval's changes).
>
> Should we change __sigemptyset/__sigfillset to fill the ununsed bits
> instead?

We would have to change sigprocmask as well.
  
Florian Weimer April 22, 2020, 12:22 p.m. UTC | #8
* Florian Weimer:

> * Adhemerval Zanella via Libc-alpha:
>
>> On 22/04/2020 07:02, Florian Weimer wrote:
>>> * Florian Weimer:
>>> 
>>>> * Andreas Schwab:
>>>>
>>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>>
>>>>>> * Andreas Schwab:
>>>>>>
>>>>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>>>>
>>>>>>>> This avoids changing the entire sigset_t structure.  Updating the
>>>>>>>> actually used part is sufficient.
>>>>>>>
>>>>>>> I'm not sure it's a good idea to leave most of the structure
>>>>>>> uninitialized.
>>>>>>
>>>>>> Would you please elaborate?  How is this different from padding?
>>>>>
>>>>> Padding is always unnamed.
>>>>
>>>> Not if it is called __glibc_reserved.  I obviously meant named
>>>> padding.
>>> 
>>> And sigprocmask has always left the padding uninitialized (even before
>>> Adhemerval's changes).
>>
>> Should we change __sigemptyset/__sigfillset to fill the ununsed bits
>> instead?
>
> We would have to change sigprocmask as well.

Just to be clear: I don't think writing more data in sigprocmask is a
useful change.  We might even have to introduce a new symbol version.
  
Adhemerval Zanella Netto April 22, 2020, 1:23 p.m. UTC | #9
On 22/04/2020 09:22, Florian Weimer wrote:
> * Florian Weimer:
> 
>> * Adhemerval Zanella via Libc-alpha:
>>
>>> On 22/04/2020 07:02, Florian Weimer wrote:
>>>> * Florian Weimer:
>>>>
>>>>> * Andreas Schwab:
>>>>>
>>>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>>>
>>>>>>> * Andreas Schwab:
>>>>>>>
>>>>>>>> On Apr 22 2020, Florian Weimer wrote:
>>>>>>>>
>>>>>>>>> This avoids changing the entire sigset_t structure.  Updating the
>>>>>>>>> actually used part is sufficient.
>>>>>>>>
>>>>>>>> I'm not sure it's a good idea to leave most of the structure
>>>>>>>> uninitialized.
>>>>>>>
>>>>>>> Would you please elaborate?  How is this different from padding?
>>>>>>
>>>>>> Padding is always unnamed.
>>>>>
>>>>> Not if it is called __glibc_reserved.  I obviously meant named
>>>>> padding.
>>>>
>>>> And sigprocmask has always left the padding uninitialized (even before
>>>> Adhemerval's changes).
>>>
>>> Should we change __sigemptyset/__sigfillset to fill the ununsed bits
>>> instead?
>>
>> We would have to change sigprocmask as well.
> 
> Just to be clear: I don't think writing more data in sigprocmask is a
> useful change.  We might even have to introduce a new symbol version.
> 

Although I considered this option on BZ#25657, I tend to agree with you.
The data is no longer accessed by GNU signal functions, so it should not 
trigger any static or sanitizer.
  
Florian Weimer May 8, 2020, 4:34 p.m. UTC | #10
* Adhemerval Zanella via Libc-alpha:

> On 28/04/2020 07:48, Florian Weimer wrote:
>> Any additional comments on this patch?  Thanks.
>> 
>
> LGTM, thanks.

Thanks, I pushed this without the spurious __glibc_unlikely change.
  

Patch

diff --git a/signal/sigempty.c b/signal/sigempty.c
index 794e449997..e9f3b571b6 100644
--- a/signal/sigempty.c
+++ b/signal/sigempty.c
@@ -17,20 +17,19 @@ 
 
 #include <errno.h>
 #include <signal.h>
-#include <string.h>
+#include <sigsetops.h>
 
 /* Clear all signals from SET.  */
 int
 sigemptyset (sigset_t *set)
 {
-  if (set == NULL)
+  if (__glibc_unlikely (set == NULL))
     {
       __set_errno (EINVAL);
       return -1;
     }
 
-  memset (set, 0, sizeof (sigset_t));
-
+  __sigemptyset (set);
   return 0;
 }
 libc_hidden_def (sigemptyset)
diff --git a/signal/sigfillset.c b/signal/sigfillset.c
index 0ca8b6b534..29e98a5864 100644
--- a/signal/sigfillset.c
+++ b/signal/sigfillset.c
@@ -17,8 +17,8 @@ 
 
 #include <errno.h>
 #include <signal.h>
-#include <string.h>
 #include <internal-signals.h>
+#include <sigsetops.h>
 
 /* Set all signals in SET.  */
 int
@@ -30,10 +30,8 @@  sigfillset (sigset_t *set)
       return -1;
     }
 
-  memset (set, 0xff, sizeof (sigset_t));
-
+  __sigfillset (set);
   __clear_internal_signals (set);
-
   return 0;
 }
 libc_hidden_def (sigfillset)