]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
usb: gadget: composite: Fix possible double free memory bug
authorChandana Kishori Chiluveru <cchiluve@codeaurora.org>
Tue, 1 Oct 2019 07:46:48 +0000 (13:16 +0530)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 26 Nov 2019 12:16:13 +0000 (13:16 +0100)
commitfa14842789850ad35be5defadacb73edb1879fec
tree55830deb2f4f6910faa8f1c2904caba59dbd542a
parentbeccb92fc3cfdba5c37633b69e6de580fe0875b2
usb: gadget: composite: Fix possible double free memory bug

BugLink: https://bugs.launchpad.net/bugs/1853519
[ Upstream commit 1c20c89b0421b52b2417bb0f62a611bc669eda1d ]

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: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/usb/gadget/composite.c