]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/rds: Avoid potential use after free in rds_send_remove_from_sock
authorAditya Pakki <pakki001@umn.edu>
Wed, 7 Apr 2021 00:09:12 +0000 (19:09 -0500)
committerDavid S. Miller <davem@davemloft.net>
Wed, 7 Apr 2021 21:01:24 +0000 (14:01 -0700)
In case of rs failure in rds_send_remove_from_sock(), the 'rm' resource
is freed and later under spinlock, causing potential use-after-free.
Set the free pointer to NULL to avoid undefined behavior.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/rds/message.c
net/rds/send.c

index 799034e0f513d988334280186cbdf255fbf50eb7..4fc66ff0f1ece01b3715dc442854d51f5508fc17 100644 (file)
@@ -180,6 +180,7 @@ void rds_message_put(struct rds_message *rm)
                rds_message_purge(rm);
 
                kfree(rm);
+               rm = NULL;
        }
 }
 EXPORT_SYMBOL_GPL(rds_message_put);
index 985d0b7713acc5f0f3e31c5944348322e3879c5f..fe5264b9d4b36aaebfc27b6f3354d750bf8e22d5 100644 (file)
@@ -665,7 +665,7 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
 unlock_and_drop:
                spin_unlock_irqrestore(&rm->m_rs_lock, flags);
                rds_message_put(rm);
-               if (was_on_sock)
+               if (was_on_sock && rm)
                        rds_message_put(rm);
        }