net: convert sock.sk_wmem_alloc from atomic_t to refcount_t
refcount_t type and corresponding API should be used instead of atomic_t when the variable is used as a reference counter. This allows to avoid accidental refcounter overflows that might lead to use-after-free situations. Signed-off-by: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David Windsor <dwindsor@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
2638595afc
commit
14afee4b60
@@ -390,7 +390,7 @@ struct sock {
|
||||
|
||||
/* ===== cache line for TX ===== */
|
||||
int sk_wmem_queued;
|
||||
atomic_t sk_wmem_alloc;
|
||||
refcount_t sk_wmem_alloc;
|
||||
unsigned long sk_tsq_flags;
|
||||
struct sk_buff *sk_send_head;
|
||||
struct sk_buff_head sk_write_queue;
|
||||
@@ -1911,7 +1911,7 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro
|
||||
*/
|
||||
static inline int sk_wmem_alloc_get(const struct sock *sk)
|
||||
{
|
||||
return atomic_read(&sk->sk_wmem_alloc) - 1;
|
||||
return refcount_read(&sk->sk_wmem_alloc) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2055,7 +2055,7 @@ static inline unsigned long sock_wspace(struct sock *sk)
|
||||
int amt = 0;
|
||||
|
||||
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
|
||||
amt = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
|
||||
amt = sk->sk_sndbuf - refcount_read(&sk->sk_wmem_alloc);
|
||||
if (amt < 0)
|
||||
amt = 0;
|
||||
}
|
||||
@@ -2136,7 +2136,7 @@ bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag);
|
||||
*/
|
||||
static inline bool sock_writeable(const struct sock *sk)
|
||||
{
|
||||
return atomic_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1);
|
||||
return refcount_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1);
|
||||
}
|
||||
|
||||
static inline gfp_t gfp_any(void)
|
||||
|
||||
Reference in New Issue
Block a user