[20/45] signal: Replace BUG_ON()s

Message ID 20230606142032.151323086@linutronix.de
State New
Headers
Series posix-timers: Cure inconsistencies and the SIG_IGN mess |

Commit Message

Thomas Gleixner June 6, 2023, 2:37 p.m. UTC
  These really can be handled gracefully without killing the machine.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/signal.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
  

Comments

Frederic Weisbecker July 4, 2023, 10:24 a.m. UTC | #1
On Tue, Jun 06, 2023 at 04:37:50PM +0200, Thomas Gleixner wrote:
> These really can be handled gracefully without killing the machine.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  kernel/signal.c |   11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1932,10 +1932,11 @@ struct sigqueue *sigqueue_alloc(void)
>  
>  void sigqueue_free(struct sigqueue *q)
>  {
> -	unsigned long flags;
>  	spinlock_t *lock = &current->sighand->siglock;
> +	unsigned long flags;
>  
> -	BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
> +	if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC)))
> +		return;
>  	/*
>  	 * We must hold ->siglock while testing q->list
>  	 * to serialize with collect_signal() or with
> @@ -1963,7 +1964,10 @@ int send_sigqueue(struct sigqueue *q, st
>  	unsigned long flags;
>  	int ret, result;
>  
> -	BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
> +	if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC)))
> +		return 0;
> +	if (WARN_ON_ONCE(q->info.si_code != SI_TIMER))
> +		return 0;

Previously it only forbid _requeuing_ other things than posix timers.
Now it only allows posix timers at all.

But anyway posix timers is the only user so far:

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>


>  
>  	ret = -1;
>  	rcu_read_lock();
> @@ -1998,7 +2002,6 @@ int send_sigqueue(struct sigqueue *q, st
>  		 * If an SI_TIMER entry is already queue just increment
>  		 * the overrun count.
>  		 */
> -		BUG_ON(q->info.si_code != SI_TIMER);
>  		q->info.si_overrun++;
>  		result = TRACE_SIGNAL_ALREADY_PENDING;
>  		goto out;
>
  

Patch

--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1932,10 +1932,11 @@  struct sigqueue *sigqueue_alloc(void)
 
 void sigqueue_free(struct sigqueue *q)
 {
-	unsigned long flags;
 	spinlock_t *lock = &current->sighand->siglock;
+	unsigned long flags;
 
-	BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
+	if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC)))
+		return;
 	/*
 	 * We must hold ->siglock while testing q->list
 	 * to serialize with collect_signal() or with
@@ -1963,7 +1964,10 @@  int send_sigqueue(struct sigqueue *q, st
 	unsigned long flags;
 	int ret, result;
 
-	BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
+	if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC)))
+		return 0;
+	if (WARN_ON_ONCE(q->info.si_code != SI_TIMER))
+		return 0;
 
 	ret = -1;
 	rcu_read_lock();
@@ -1998,7 +2002,6 @@  int send_sigqueue(struct sigqueue *q, st
 		 * If an SI_TIMER entry is already queue just increment
 		 * the overrun count.
 		 */
-		BUG_ON(q->info.si_code != SI_TIMER);
 		q->info.si_overrun++;
 		result = TRACE_SIGNAL_ALREADY_PENDING;
 		goto out;