Received: by 10.192.165.148 with SMTP id m20csp2542070imm; Sun, 22 Apr 2018 09:11:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+jV0nrWZG6iffNyQBSB8VYDbVeDbA+UOyPYM/fApa+POad/vOlpVFVedGllBoj27UYFR61 X-Received: by 10.98.104.199 with SMTP id d190mr16870939pfc.111.1524413502114; Sun, 22 Apr 2018 09:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524413502; cv=none; d=google.com; s=arc-20160816; b=XnhdWfUd3xE2WRx+mUEAiFZ5BoqVL43KFN6/+iUhVI0rraBEryrN0UqKEbxUtMuB87 82v5FpvUt7qiPtpD/P+Zbs6RT2ICakg4vjAF53Iv3cFRxaYlgQPZ/CBQTAyKcBL/85+R uAlVK9T3RbGwH38s7mfX1fQx4xS0rsYYlhcRlxssIvF7k+g+8sWWlNnBwI5sWXRvtDsi gAv26QBZOKB6RHMeQvgCFD0vynSvGESPTREDlNfIS47YH92t3nlKWbO/F+/dwlcmmCM4 axk6K/bJCxEIah0+PTmiygFIZv3wLfEyLoyvixGAu56Wl1dwgS7M3YaTq9Jjv4B57S4J 3KJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=7dB69dvaTI7SGW2cgmdPXn51waSYnpoD90XMsz8zOGM=; b=tWQy9cy9o+VwI/OzJ3mOFuOYkmuuatneFYeSq+0G26CmJUqVVyMjPmLTyZ8cJIpVyW JLalY9F1hBJfPq33Ul7wjClCo3GJNVXgHiNK6zSCyxM+2Gb2CjfKIdMhNpS/RmYwmRTw xNJoB3yHkw3z4WiPRz9Glrgb0iSrZD2vymZvHPrTJRzn5L9iAG13kIz9zQFHlcyA/7jz 8XAAzx0eP2Xu7Bm9BpR+dSZ9MaTYe8TuUIn8KNkxFjJq2tyRbZBh/2a7tXNCJlR7G+eY TcjrllSLpBNvQw9HpuVC0FPLujyBFEXGSEWFbBtsBApjJAToLzwJsJnRsVnpwErUazhJ a9nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si9951670pld.69.2018.04.22.09.11.28; Sun, 22 Apr 2018 09:11:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753987AbeDVQK1 (ORCPT + 99 others); Sun, 22 Apr 2018 12:10:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44964 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751710AbeDVN4K (ORCPT ); Sun, 22 Apr 2018 09:56:10 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D64158FF; Sun, 22 Apr 2018 13:56:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tuba Yavuz , Felipe Balbi Subject: [PATCH 4.16 040/196] USB: gadget: f_midi: fixing a possible double-free in f_midi Date: Sun, 22 Apr 2018 15:51:00 +0200 Message-Id: <20180422135106.154436732@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yavuz, Tuba commit 7fafcfdf6377b18b2a726ea554d6e593ba44349f upstream. It looks like there is a possibility of a double-free vulnerability on an error path of the f_midi_set_alt function in the f_midi driver. If the path is feasible then free_ep_req gets called twice: req->complete = f_midi_complete; err = usb_ep_queue(midi->out_ep, req, GFP_ATOMIC); => ... usb_gadget_giveback_request => f_midi_complete (CALLBACK) (inside f_midi_complete, for various cases of status) free_ep_req(ep, req); // first kfree if (err) { ERROR(midi, "%s: couldn't enqueue request: %d\n", midi->out_ep->name, err); free_ep_req(midi->out_ep, req); // second kfree return err; } The double-free possibility was introduced with commit ad0d1a058eac ("usb: gadget: f_midi: fix leak on failed to enqueue out requests"). Found by MOXCAFE tool. Signed-off-by: Tuba Yavuz Fixes: ad0d1a058eac ("usb: gadget: f_midi: fix leak on failed to enqueue out requests") Acked-by: Felipe Balbi Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_midi.c | 3 ++- drivers/usb/gadget/u_f.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -404,7 +404,8 @@ static int f_midi_set_alt(struct usb_fun if (err) { ERROR(midi, "%s: couldn't enqueue request: %d\n", midi->out_ep->name, err); - free_ep_req(midi->out_ep, req); + if (req->buf != NULL) + free_ep_req(midi->out_ep, req); return err; } } --- a/drivers/usb/gadget/u_f.h +++ b/drivers/usb/gadget/u_f.h @@ -61,7 +61,9 @@ struct usb_request *alloc_ep_req(struct /* Frees a usb_request previously allocated by alloc_ep_req() */ static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req) { + WARN_ON(req->buf == NULL); kfree(req->buf); + req->buf = NULL; usb_ep_free_request(ep, req); }