@@ -541,20 +541,22 @@ static void kauditd_printk_skb(struct sk_buff *skb)
541
541
/**
542
542
* kauditd_rehold_skb - Handle a audit record send failure in the hold queue
543
543
* @skb: audit record
544
+ * @error: error code (unused)
544
545
*
545
546
* Description:
546
547
* This should only be used by the kauditd_thread when it fails to flush the
547
548
* hold queue.
548
549
*/
549
- static void kauditd_rehold_skb (struct sk_buff * skb )
550
+ static void kauditd_rehold_skb (struct sk_buff * skb , __always_unused int error )
550
551
{
551
- /* put the record back in the queue at the same place */
552
- skb_queue_head (& audit_hold_queue , skb );
552
+ /* put the record back in the queue */
553
+ skb_queue_tail (& audit_hold_queue , skb );
553
554
}
554
555
555
556
/**
556
557
* kauditd_hold_skb - Queue an audit record, waiting for auditd
557
558
* @skb: audit record
559
+ * @error: error code
558
560
*
559
561
* Description:
560
562
* Queue the audit record, waiting for an instance of auditd. When this
@@ -564,19 +566,31 @@ static void kauditd_rehold_skb(struct sk_buff *skb)
564
566
* and queue it, if we have room. If we want to hold on to the record, but we
565
567
* don't have room, record a record lost message.
566
568
*/
567
- static void kauditd_hold_skb (struct sk_buff * skb )
569
+ static void kauditd_hold_skb (struct sk_buff * skb , int error )
568
570
{
569
571
/* at this point it is uncertain if we will ever send this to auditd so
570
572
* try to send the message via printk before we go any further */
571
573
kauditd_printk_skb (skb );
572
574
573
575
/* can we just silently drop the message? */
574
- if (!audit_default ) {
575
- kfree_skb (skb );
576
- return ;
576
+ if (!audit_default )
577
+ goto drop ;
578
+
579
+ /* the hold queue is only for when the daemon goes away completely,
580
+ * not -EAGAIN failures; if we are in a -EAGAIN state requeue the
581
+ * record on the retry queue unless it's full, in which case drop it
582
+ */
583
+ if (error == - EAGAIN ) {
584
+ if (!audit_backlog_limit ||
585
+ skb_queue_len (& audit_retry_queue ) < audit_backlog_limit ) {
586
+ skb_queue_tail (& audit_retry_queue , skb );
587
+ return ;
588
+ }
589
+ audit_log_lost ("kauditd retry queue overflow" );
590
+ goto drop ;
577
591
}
578
592
579
- /* if we have room, queue the message */
593
+ /* if we have room in the hold queue , queue the message */
580
594
if (!audit_backlog_limit ||
581
595
skb_queue_len (& audit_hold_queue ) < audit_backlog_limit ) {
582
596
skb_queue_tail (& audit_hold_queue , skb );
@@ -585,24 +599,32 @@ static void kauditd_hold_skb(struct sk_buff *skb)
585
599
586
600
/* we have no other options - drop the message */
587
601
audit_log_lost ("kauditd hold queue overflow" );
602
+ drop :
588
603
kfree_skb (skb );
589
604
}
590
605
591
606
/**
592
607
* kauditd_retry_skb - Queue an audit record, attempt to send again to auditd
593
608
* @skb: audit record
609
+ * @error: error code (unused)
594
610
*
595
611
* Description:
596
612
* Not as serious as kauditd_hold_skb() as we still have a connected auditd,
597
613
* but for some reason we are having problems sending it audit records so
598
614
* queue the given record and attempt to resend.
599
615
*/
600
- static void kauditd_retry_skb (struct sk_buff * skb )
616
+ static void kauditd_retry_skb (struct sk_buff * skb , __always_unused int error )
601
617
{
602
- /* NOTE: because records should only live in the retry queue for a
603
- * short period of time, before either being sent or moved to the hold
604
- * queue, we don't currently enforce a limit on this queue */
605
- skb_queue_tail (& audit_retry_queue , skb );
618
+ if (!audit_backlog_limit ||
619
+ skb_queue_len (& audit_retry_queue ) < audit_backlog_limit ) {
620
+ skb_queue_tail (& audit_retry_queue , skb );
621
+ return ;
622
+ }
623
+
624
+ /* we have to drop the record, send it via printk as a last effort */
625
+ kauditd_printk_skb (skb );
626
+ audit_log_lost ("kauditd retry queue overflow" );
627
+ kfree_skb (skb );
606
628
}
607
629
608
630
/**
@@ -640,7 +662,7 @@ static void auditd_reset(const struct auditd_connection *ac)
640
662
/* flush the retry queue to the hold queue, but don't touch the main
641
663
* queue since we need to process that normally for multicast */
642
664
while ((skb = skb_dequeue (& audit_retry_queue )))
643
- kauditd_hold_skb (skb );
665
+ kauditd_hold_skb (skb , - ECONNREFUSED );
644
666
}
645
667
646
668
/**
@@ -714,24 +736,26 @@ static int kauditd_send_queue(struct sock *sk, u32 portid,
714
736
struct sk_buff_head * queue ,
715
737
unsigned int retry_limit ,
716
738
void (* skb_hook )(struct sk_buff * skb ),
717
- void (* err_hook )(struct sk_buff * skb ))
739
+ void (* err_hook )(struct sk_buff * skb , int error ))
718
740
{
719
741
int rc = 0 ;
720
- struct sk_buff * skb ;
742
+ struct sk_buff * skb = NULL ;
743
+ struct sk_buff * skb_tail ;
721
744
unsigned int failed = 0 ;
722
745
723
746
/* NOTE: kauditd_thread takes care of all our locking, we just use
724
747
* the netlink info passed to us (e.g. sk and portid) */
725
748
726
- while ((skb = skb_dequeue (queue ))) {
749
+ skb_tail = skb_peek_tail (queue );
750
+ while ((skb != skb_tail ) && (skb = skb_dequeue (queue ))) {
727
751
/* call the skb_hook for each skb we touch */
728
752
if (skb_hook )
729
753
(* skb_hook )(skb );
730
754
731
755
/* can we send to anyone via unicast? */
732
756
if (!sk ) {
733
757
if (err_hook )
734
- (* err_hook )(skb );
758
+ (* err_hook )(skb , - ECONNREFUSED );
735
759
continue ;
736
760
}
737
761
@@ -745,7 +769,7 @@ static int kauditd_send_queue(struct sock *sk, u32 portid,
745
769
rc == - ECONNREFUSED || rc == - EPERM ) {
746
770
sk = NULL ;
747
771
if (err_hook )
748
- (* err_hook )(skb );
772
+ (* err_hook )(skb , rc );
749
773
if (rc == - EAGAIN )
750
774
rc = 0 ;
751
775
/* continue to drain the queue */
0 commit comments