Skip to content

Commit f194db6

Browse files
committed
fw/cache: Do not take an additional reference on paged sk_buff fragment
while copying http/2 response body Taking additional reference on paged sk_buff fragment is not needed when building http/2 response body because each fragment is represented by newly allocated page with page->_refcount == 1. Extra page reference would result in memory leak during sk_buff freeing because of non-zero page->_refcount, so final __put_page() would not be called. For http/1 responses we still need an additional page reference due to the fact that the page in question has actually been allocated previously by TDB (see tdb_file_open()). Missing an additional reference here would lead to TDB owned pages freeing by kfree_skb(), which in turn would cause memory corruption. Signed-off-by: Petr Vyazovik <xen@f-m.fm>
1 parent 36531dd commit f194db6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

fw/cache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,8 @@ tfw_cache_add_body_page(TfwMsgIter *it, char *p, int sz, TfwFrameHdr *frame_hdr,
22512251

22522252
++it->frag;
22532253
skb_fill_page_desc(it->skb, it->frag, page, off, sz);
2254-
skb_frag_ref(it->skb, it->frag);
2254+
if (!h2)
2255+
skb_frag_ref(it->skb, it->frag);
22552256
ss_skb_adjust_data_len(it->skb, sz);
22562257

22572258
return 0;

fw/http.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4807,7 +4807,6 @@ tfw_h2_append_predefined_body(TfwHttpResp *resp, unsigned int stream_id,
48074807
++it->frag;
48084808
skb_fill_page_desc(it->skb, it->frag, page, 0,
48094809
copy + FRAME_HEADER_SIZE);
4810-
skb_frag_ref(it->skb, it->frag);
48114810
ss_skb_adjust_data_len(it->skb, copy + FRAME_HEADER_SIZE);
48124811

48134812
if (it->frag + 1 == MAX_SKB_FRAGS

0 commit comments

Comments
 (0)