Received: by 10.192.165.148 with SMTP id m20csp2490721imm; Sun, 22 Apr 2018 08:07:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx48vEGTCvDp6sFu2q4+Rl7AAogiyZ9YTh/Xi8pN8UW8pcs9vy1NUtaGR2At3Jlot/xyz/RW3 X-Received: by 10.99.97.151 with SMTP id v145mr14689848pgb.35.1524409621458; Sun, 22 Apr 2018 08:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409621; cv=none; d=google.com; s=arc-20160816; b=ke7yba6udHSArctVI0l3CbCunKU3wiTd3HiDIJ2eVp1DRELm84lDOC2vc3LQIf5Lpj 29Hd/3DCy2oR8QFDGBiRspcPbzknRACF8YWEsQG8F49Aw9Az+GdcC4N/q/Dke7d4m+2F AMs35lOjoRc1aTuzR1zZGoMeQK/fEloCXJmsr6d3SCWjX7joaB4thK8+NwwaOF01YfMR gyvIF+tZOCkIWEtRxeCMQKbJroJkV6seqWRw64YuxOqlOCMpAtBTOss7O5XLSsPG2Krd Na9yHOCpPM5QEagaCcOswMTExwg7oS7vY80PUEulzoC2CWhyhDgM5fijavVtjnJjb606 MocA== 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=JR7DsSgJe2xwe1v58mQHtYb4i1g8aGgMjBfCIOiuykI=; b=PPNPX3QslhuQbbTnfFT3RbVJuKEJ1UH5CJPpPvPSx7JCBTM7l8u6bUXdWwYbzJoQGV Si+VBMpZWiHwYl9VGZYdVdtKMxhCbg7PUWER2PfeZiDii9ZMYVnTpzsWqWM2CT9PCAwl otKMlercVSqzA0cUANHg394C+M0XorcIK5Z30g/dTq/mhjNZZCc/YeJNOhUqGASm88pV Npa7RYBEAbPDP1D7UoMT4Clmjeo94C5OljG27vlCCVheu4wILOhaHUS2YFlqCaq6fbrE 2kMjBKL3TJjkqjr1vEtpQCWN9hLEb8fReUCFUEevfnO1JG/bjQ+fHoQo8Xdw/H1Ump11 e7PQ== 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 f1-v6si9680455pld.168.2018.04.22.08.06.47; Sun, 22 Apr 2018 08:07:01 -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 S1755002AbeDVPFt (ORCPT + 99 others); Sun, 22 Apr 2018 11:05:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54504 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756543AbeDVOLk (ORCPT ); Sun, 22 Apr 2018 10:11:40 -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 C3586CB0; Sun, 22 Apr 2018 14:11:39 +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.9 20/95] USB: gadget: f_midi: fixing a possible double-free in f_midi Date: Sun, 22 Apr 2018 15:52:49 +0200 Message-Id: <20180422135211.266586357@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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.9-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 @@ -389,7 +389,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 @@ -64,7 +64,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); }