Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9178346pxu; Mon, 28 Dec 2020 08:31:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE2eIG9uzWTCysEgejKPTrjvZtASUplW9j2fDUcQf30diXT/SQNGBTnu73WO3ITM9z+Jn1 X-Received: by 2002:a17:906:1197:: with SMTP id n23mr42661586eja.359.1609173096543; Mon, 28 Dec 2020 08:31:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173096; cv=none; d=google.com; s=arc-20160816; b=J74vfUA0g2w77tEL1M+roAy8OUclrSAAvZkB7LIAVsKpi9ScZ/ixyYMWCUcC3aqaR/ FdeZ0MMSdFUJE9P5xQyXynMivEulcarvAQIUd9xyTvqykg6PduOab6qEJ+fgX7UZ7oj/ 5bftU2iU/X0iTntMmjTtX6lv0A2HzcnwJKT02Hh23oYV4mcPq4Yaee6kS2TajS2O4KLS ynXTgsGAxxcGXc9CJo/WnhleM9l9rw2E95r26TO5l6qWeknKfL1ZPDTQUkDFRFohpabj N8i/zI4XSY9dXOVXqCbjtObYsZnCr7NN1vLhwH2BAM4mknuYQH3EhetveXXRx04CfYTG pZ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TlXOFdzjlVnxRW7KukBihCnOJTTBKTnf10B6pfQTBKo=; b=nkCGAmGBzElgg5mp0Pi/ZgXNE/3MKgN/9UCCfs1UsplQ0vsW+ycm4wZScpS2yynwLS VoZp0q2k7RCbGM/ZubemjGBLFVaL2kTVNxWL70hO/C5pL/AgcOo3s04yg125W70Sakfi dEL+nvdMsVHNO/jSvZ7MkYtxavx02rjdBE8FcKtcEp05R/93G/HMWPTbJ/5TuvDrMnw2 6n9Zti2RtKM2oNkeBNNDefjzayzddkTvd1bnO8J4JljQMtSXEIX5MQsnx+/j2Ys3Mcu4 uv09aGgCMfcQCNo2p/XUgdznIDNrsHldsCTA4pRbk/U/25fadC/wnQdeqWjHRm0V3NCq Nvnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TSx7CPVe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr5si18235951ejb.59.2020.12.28.08.31.13; Mon, 28 Dec 2020 08:31:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TSx7CPVe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731052AbgL1NJF (ORCPT + 99 others); Mon, 28 Dec 2020 08:09:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:36046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731011AbgL1NIz (ORCPT ); Mon, 28 Dec 2020 08:08:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 02C032076D; Mon, 28 Dec 2020 13:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160919; bh=PsggyikTz3ZfDUADG0zA8/DVJ2pK+14Uh7TcdsbIcjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TSx7CPVe3IeXcllWKLh9V9Bv+kQl1tgsLpY0UZ9OdveKswcp0XkTlVU2rtHIFyg+s mFaU/Vcl3jMFgb+4G9pa/eGeHMCAcWNt2rMY4DGaL3YagfdKzRJguy3E3wThRKQAV1 z3Vk66JB/QAqG8z88/Y33lbJy+xp8S6+VAvQoA5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Lunn , Baruch Siach , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 4.14 038/242] gpio: mvebu: fix potential user-after-free on probe Date: Mon, 28 Dec 2020 13:47:23 +0100 Message-Id: <20201228124906.543278032@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baruch Siach [ Upstream commit 7ee1a01e47403f72b9f38839a737692f6991263e ] When mvebu_pwm_probe() fails IRQ domain is not released. Move pwm probe before IRQ domain allocation. Add pwm cleanup code to the failure path. Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support") Reported-by: Andrew Lunn Signed-off-by: Baruch Siach Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- drivers/gpio/gpio-mvebu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c index be85d4b39e997..fc762b4adcb22 100644 --- a/drivers/gpio/gpio-mvebu.c +++ b/drivers/gpio/gpio-mvebu.c @@ -1195,6 +1195,13 @@ static int mvebu_gpio_probe(struct platform_device *pdev) devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip); + /* Some MVEBU SoCs have simple PWM support for GPIO lines */ + if (IS_ENABLED(CONFIG_PWM)) { + err = mvebu_pwm_probe(pdev, mvchip, id); + if (err) + return err; + } + /* Some gpio controllers do not provide irq support */ if (!have_irqs) return 0; @@ -1204,7 +1211,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev) if (!mvchip->domain) { dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n", mvchip->chip.label); - return -ENODEV; + err = -ENODEV; + goto err_pwm; } err = irq_alloc_domain_generic_chips( @@ -1252,14 +1260,12 @@ static int mvebu_gpio_probe(struct platform_device *pdev) mvchip); } - /* Some MVEBU SoCs have simple PWM support for GPIO lines */ - if (IS_ENABLED(CONFIG_PWM)) - return mvebu_pwm_probe(pdev, mvchip, id); - return 0; err_domain: irq_domain_remove(mvchip->domain); +err_pwm: + pwmchip_remove(&mvchip->mvpwm->chip); return err; } -- 2.27.0