Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3767345pxt; Tue, 10 Aug 2021 10:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypJmGO73LMxnW5M1b7xoSWL7fWegtsF+HHWjGIS44pC9t5Rfpmipxtfcsns1ZmmP5ml83+ X-Received: by 2002:a02:5107:: with SMTP id s7mr28537953jaa.65.1628617860901; Tue, 10 Aug 2021 10:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617860; cv=none; d=google.com; s=arc-20160816; b=i4Tcz/bBXzvHqR4ZOlBVSSbpNY64eBBWaKa0Q6/mMZVLi68Dof20LK16Lzz4PsoqAg hsj2+eF1PT+9M2uphGzKdMbdkeK/lhis2DK7lynusBkjYREvnypQo0UMKSedqcOdP9fU RfqJzuvdt6iZtdevgt3ZgsDe/AOmJU5zssdmPiQYh2EzQoJt2zeGWI2rA8jW3kOV6cAm WyBOTqmLs/VbvItlq2rOuwyCrtj8/F4mft9J1WGMtQhioSq1ZNiTpVOBBSoeSoJuXq8m 0lzVrB8WOV7VVdagJAxLvI7FReJLatlLlb2SVdPbT6msjonmwyggHRemtaSfJJhBJSZF YzjQ== 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=jIxWkj7G7evkfcpcUTV8LcqKnlzCaorGRPRFdg06KFU=; b=t/39T3ZmcUvGOTZSpaJgXDPpGNfwJ/At4/nEZUYssrqSO269BzaIrbSSmiCCnPfVum M7iTRw7EyXt/dFauQ1zUB+zOHS+JG0HiX39AcCW1+VJwjpq5YxFA0uIC3haIuuefTzZ/ 49VMjkLqMrjH5KsPlerqKCveY4JTvid5EQXsxdZo01ofk8evKWkmS/XJ/APxx5zUlkZr jPtu37sQsZHGkw2+L7/7jptIdABz7ogDYeA5RXsO+B9QdRWn0CvoA97qhLj98AP2gHMK 1SDhaJlZE6ybEGo1GqQcQucSWCbheGQiPl11JoRNQ7md47ZqWmK3lk+iX+70PHWekiFG 0sqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ldWQhvuZ; 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 f10si26672695ila.58.2021.08.10.10.50.49; Tue, 10 Aug 2021 10:51:00 -0700 (PDT) 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=ldWQhvuZ; 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 S234330AbhHJRsP (ORCPT + 99 others); Tue, 10 Aug 2021 13:48:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:53276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234811AbhHJRpL (ORCPT ); Tue, 10 Aug 2021 13:45:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5706461242; Tue, 10 Aug 2021 17:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617202; bh=fKoEumaFyE1JrCXckW1t74vFD5tL6y967iFPZNEBLBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ldWQhvuZf8w3Pkfg4FeioCAptfcuzE44raZJfERsVpG2ue5gHcyuuy57LBGwma1Oc wWoo+vK1euUIpXgnoNBlURaImZkwOR6VMpi0cRgNJjNWlwM7rnYPOgrcgZlo4lJVTP Ohkgx9v7TdDmM4Zmnf3RNzB5317v3SCCAqLITbxI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filip Schauer Subject: [PATCH 5.10 090/135] drivers core: Fix oops when driver probe fails Date: Tue, 10 Aug 2021 19:30:24 +0200 Message-Id: <20210810172958.822424579@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@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: Filip Schauer commit 4d1014c1816c0395eca5d1d480f196a4c63119d0 upstream. dma_range_map is freed to early, which might cause an oops when a driver probe fails. Call trace: is_free_buddy_page+0xe4/0x1d4 __free_pages+0x2c/0x88 dma_free_contiguous+0x64/0x80 dma_direct_free+0x38/0xb4 dma_free_attrs+0x88/0xa0 dmam_release+0x28/0x34 release_nodes+0x78/0x8c devres_release_all+0xa8/0x110 really_probe+0x118/0x2d0 __driver_probe_device+0xc8/0xe0 driver_probe_device+0x54/0xec __driver_attach+0xe0/0xf0 bus_for_each_dev+0x7c/0xc8 driver_attach+0x30/0x3c bus_add_driver+0x17c/0x1c4 driver_register+0xc0/0xf8 __platform_driver_register+0x34/0x40 ... This issue is introduced by commit d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe failed"). It frees dma_range_map before the call to devres_release_all, which is too early. The solution is to free dma_range_map only after devres_release_all. Fixes: d0243bbd5dd3 ("drivers core: Free dma_range_map when driver probe failed") Cc: stable Signed-off-by: Filip Schauer Link: https://lore.kernel.org/r/20210727112311.GA7645@DESKTOP-E8BN1B0.localdomain Signed-off-by: Greg Kroah-Hartman --- drivers/base/dd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -617,8 +617,6 @@ dev_groups_failed: else if (drv->remove) drv->remove(dev); probe_failed: - kfree(dev->dma_range_map); - dev->dma_range_map = NULL; if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DRIVER_NOT_BOUND, dev); @@ -626,6 +624,8 @@ pinctrl_bind_failed: device_links_no_driver(dev); devres_release_all(dev); arch_teardown_dma_ops(dev); + kfree(dev->dma_range_map); + dev->dma_range_map = NULL; driver_sysfs_remove(dev); dev->driver = NULL; dev_set_drvdata(dev, NULL);