Skip to content
Snippets Groups Projects
  • Hyunwoo Kim's avatar
    HID: roccat: Fix use-after-free in roccat_read() · 4d870684
    Hyunwoo Kim authored
    mainline inclusion
    from mainline master
    commit cacdb14b1c8d3804a3a7d31773bc7569837b71a4
    category: bugfix
    bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5U1PE
    CVE: CVE-2022-41850
    
    --------------------------------
    
    roccat_report_event() is responsible for registering
    roccat-related reports in struct roccat_device.
    
    int roccat_report_event(int minor, u8 const *data)
    {
    	struct roccat_device *device;
    	struct roccat_reader *reader;
    	struct roccat_report *report;
    	uint8_t *new_value;
    
    	device = devices[minor];
    
    	new_value = kmemdup(data, device->report_size, GFP_ATOMIC);
    	if (!new_value)
    		return -ENOMEM;
    
    	report = &device->cbuf[device->cbuf_end];
    
    	/* passing NULL is safe */
    	kfree(report->value);
    	...
    
    The registered report is stored in the struct roccat_device member
    "struct roccat_report cbuf[ROCCAT_CBUF_SIZE];".
    If more reports are received than the "ROCCAT_CBUF_SIZE" value,
    kfree() the saved report from cbuf[0] and allocates a new reprot.
    Since th...
    4d870684