Skip to content

Commit 5e470b6

Browse files
Chandana Kishori ChiluveruLee Jones
authored andcommitted
usb: gadget: composite: Fix possible double free memory bug
[ Upstream commit 1c20c89 ] composite_dev_cleanup call from the failure of configfs_composite_bind frees up the cdev->os_desc_req and cdev->req. If the previous calls of bind and unbind is successful these will carry stale values. Consider the below sequence of function calls: configfs_composite_bind() composite_dev_prepare() - Allocate cdev->req, cdev->req->buf composite_os_desc_req_prepare() - Allocate cdev->os_desc_req, cdev->os_desc_req->buf configfs_composite_unbind() composite_dev_cleanup() - free the cdev->os_desc_req->buf and cdev->req->buf Next composition switch configfs_composite_bind() - If it fails goto err_comp_cleanup will call the composite_dev_cleanup() function composite_dev_cleanup() - calls kfree up with the stale values of cdev->req->buf and cdev->os_desc_req from the previous configfs_composite_bind call. The free call on these stale values leads to double free. Hence, Fix this issue by setting request and buffer pointer to NULL after kfree. Signed-off-by: Chandana Kishori Chiluveru <cchiluve@codeaurora.org> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Lee Jones <lee.jones@linaro.org> Change-Id: I4ffa7f7e2bcbac44a11dd13bd8d404392a71ea6a
1 parent 3be639a commit 5e470b6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/usb/gadget/composite.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,11 +1968,15 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev)
19681968
}
19691969
if (cdev->os_desc_req) {
19701970
kfree(cdev->os_desc_req->buf);
1971+
cdev->os_desc_req->buf = NULL;
19711972
usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req);
1973+
cdev->os_desc_req = NULL;
19721974
}
19731975
if (cdev->req) {
19741976
kfree(cdev->req->buf);
1977+
cdev->req->buf = NULL;
19751978
usb_ep_free_request(cdev->gadget->ep0, cdev->req);
1979+
cdev->req = NULL;
19761980
}
19771981
cdev->next_string_id = 0;
19781982
device_remove_file(&cdev->gadget->dev, &dev_attr_suspended);

0 commit comments

Comments
 (0)