Re: [PATCH net v2] nfc: llcp: reject PDUs shorter than the LLCP header
From: David Laight
Date: Tue Jul 14 2026 - 16:53:21 EST
On Tue, 14 Jul 2026 18:46:29 +0200
Doruk Tan Ozturk <doruk@xxxxxxx> wrote:
> > Is there a similar problem with non-linear skb?
> > Maybe they can't get into this code, but who knows what can happen
> > with unusual configs.
>
> Good question. Today every skb that reaches __nfc_llcp_recv() is
> linear: the target path (nci_rx_data_packet -> nci_add_rx_data_frag ->
> nfc_tm_data_received) and the initiator path (nfc_data_exchange ->
> nfc_llcp_recv) both build the frame with alloc_skb()/nci_skb_alloc()
> plus skb_put()/skb_put_data(), and NCI reassembly uses skb_cow_head()
> and skb_push() into the linear area. Nothing on the NFC receive side
> attaches page frags or a frag_list, so skb->len == skb_headlen() and the
> v2 skb->len test was in fact sufficient for the in-tree drivers.
>
> But relying on that is fragile: the parser reads the header out of the
> linear area (pdu->data[0]/data[1]) while skb->len is the total length,
> so a non-linear skb with a short linear head would slip past a skb->len
> test and still over-read the linear buffer. pskb_may_pull() is the
> right guard here -- it also covers the non-linear case, and it matches
> how the sibling NCI and HCI receive paths already validate their
> headers.
>
> I will send a v3 that uses:
>
> if (!pskb_may_pull(skb, LLCP_HEADER_SIZE)) {
> kfree_skb(skb);
> return;
> }
>
> That is strictly stronger than the v2 check and does not reject any
> valid frame -- pskb_may_pull() pulls the two header bytes into the
> linear area when needed.
Does that help any code further down the rx path?
It might be better to drop non-linear packets with a comment that
they aren't expected to happen.
David
>
> Thanks,
> Doruk