• Xiaomeng Tong's avatar
    media: uvcvideo: Fix missing check to determine if element is found in list · 261f3338
    Xiaomeng Tong authored
    The list iterator will point to a bogus position containing HEAD if
    the list is empty or the element is not found in list. This case
    should be checked before any use of the iterator, otherwise it will
    lead to a invalid memory access. The missing check here is before
    "pin = iterm->id;", just add check here to fix the security bug.
    
    In addition, the list iterator value will *always* be set and non-NULL
    by list_for_each_entry(), so it is incorrect to assume that the iterator
    value will be NULL if the element is not found in list, considering
    the (mis)use here: "if (iterm == NULL".
    
    Use a new value 'it' as the list iterator, while use the old value
    'iterm' as a dedicated pointer to point to the found element, which
    1. can fix this bug, due to 'iterm' is NULL only if it's not found.
    2. do not need to change all the uses of 'iterm' after the loop.
    3. can also limit the scope of the list iterator 'it' *only inside*
       the traversal loop by simply declaring 'it' inside the loop in the
       future, as usage of the iterator outside of the list_for_each_entry
       is considered harmful. https://lkml.org/lkml/2022/2/17/1032
    
    Fixes: d5e90b7a
    
     ("[media] uvcvideo: Move to video_ioctl2")
    Signed-off-by: default avatarXiaomeng Tong <xiam0nd.tong@gmail.com>
    Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
    261f3338
uvc_v4l2.c 38.3 KB