skbuff.c (e700ac213a0f793fb4f83098413303e3dd080892) | skbuff.c (7f678def99d29c520418607509bb19c7fc96a6db) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Routines having to do with the 'struct sk_buff' memory handlers. 4 * 5 * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk> 6 * Florian La Roche <rzsfl@rz.uni-sb.de> 7 * 8 * Fixes: --- 66 unchanged lines hidden (view full) --- 75#include <linux/uaccess.h> 76#include <trace/events/skb.h> 77#include <linux/highmem.h> 78#include <linux/capability.h> 79#include <linux/user_namespace.h> 80#include <linux/indirect_call_wrapper.h> 81 82#include "datagram.h" | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Routines having to do with the 'struct sk_buff' memory handlers. 4 * 5 * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk> 6 * Florian La Roche <rzsfl@rz.uni-sb.de> 7 * 8 * Fixes: --- 66 unchanged lines hidden (view full) --- 75#include <linux/uaccess.h> 76#include <trace/events/skb.h> 77#include <linux/highmem.h> 78#include <linux/capability.h> 79#include <linux/user_namespace.h> 80#include <linux/indirect_call_wrapper.h> 81 82#include "datagram.h" |
83#include "sock_destructor.h" |
|
83 84struct kmem_cache *skbuff_head_cache __ro_after_init; 85static struct kmem_cache *skbuff_fclone_cache __ro_after_init; 86#ifdef CONFIG_SKB_EXTENSIONS 87static struct kmem_cache *skbuff_ext_cache __ro_after_init; 88#endif 89int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS; 90EXPORT_SYMBOL(sysctl_max_skb_frags); --- 1708 unchanged lines hidden (view full) --- 1799 * and frees original skb in case of failures. 1800 * 1801 * It expect increased headroom and generates warning otherwise. 1802 */ 1803 1804struct sk_buff *skb_expand_head(struct sk_buff *skb, unsigned int headroom) 1805{ 1806 int delta = headroom - skb_headroom(skb); | 84 85struct kmem_cache *skbuff_head_cache __ro_after_init; 86static struct kmem_cache *skbuff_fclone_cache __ro_after_init; 87#ifdef CONFIG_SKB_EXTENSIONS 88static struct kmem_cache *skbuff_ext_cache __ro_after_init; 89#endif 90int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS; 91EXPORT_SYMBOL(sysctl_max_skb_frags); --- 1708 unchanged lines hidden (view full) --- 1800 * and frees original skb in case of failures. 1801 * 1802 * It expect increased headroom and generates warning otherwise. 1803 */ 1804 1805struct sk_buff *skb_expand_head(struct sk_buff *skb, unsigned int headroom) 1806{ 1807 int delta = headroom - skb_headroom(skb); |
1808 int osize = skb_end_offset(skb); 1809 struct sock *sk = skb->sk; |
|
1807 1808 if (WARN_ONCE(delta <= 0, 1809 "%s is expecting an increase in the headroom", __func__)) 1810 return skb; 1811 | 1810 1811 if (WARN_ONCE(delta <= 0, 1812 "%s is expecting an increase in the headroom", __func__)) 1813 return skb; 1814 |
1812 /* pskb_expand_head() might crash, if skb is shared */ 1813 if (skb_shared(skb)) { | 1815 delta = SKB_DATA_ALIGN(delta); 1816 /* pskb_expand_head() might crash, if skb is shared. */ 1817 if (skb_shared(skb) || !is_skb_wmem(skb)) { |
1814 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC); 1815 | 1818 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC); 1819 |
1816 if (likely(nskb)) { 1817 if (skb->sk) 1818 skb_set_owner_w(nskb, skb->sk); 1819 consume_skb(skb); 1820 } else { 1821 kfree_skb(skb); 1822 } | 1820 if (unlikely(!nskb)) 1821 goto fail; 1822 1823 if (sk) 1824 skb_set_owner_w(nskb, sk); 1825 consume_skb(skb); |
1823 skb = nskb; 1824 } | 1826 skb = nskb; 1827 } |
1825 if (skb && 1826 pskb_expand_head(skb, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { 1827 kfree_skb(skb); 1828 skb = NULL; | 1828 if (pskb_expand_head(skb, delta, 0, GFP_ATOMIC)) 1829 goto fail; 1830 1831 if (sk && is_skb_wmem(skb)) { 1832 delta = skb_end_offset(skb) - osize; 1833 refcount_add(delta, &sk->sk_wmem_alloc); 1834 skb->truesize += delta; |
1829 } 1830 return skb; | 1835 } 1836 return skb; |
1837 1838fail: 1839 kfree_skb(skb); 1840 return NULL; |
|
1831} 1832EXPORT_SYMBOL(skb_expand_head); 1833 1834/** 1835 * skb_copy_expand - copy and expand sk_buff 1836 * @skb: buffer to copy 1837 * @newheadroom: new free bytes at head 1838 * @newtailroom: new free bytes at tail --- 4724 unchanged lines hidden --- | 1841} 1842EXPORT_SYMBOL(skb_expand_head); 1843 1844/** 1845 * skb_copy_expand - copy and expand sk_buff 1846 * @skb: buffer to copy 1847 * @newheadroom: new free bytes at head 1848 * @newtailroom: new free bytes at tail --- 4724 unchanged lines hidden --- |