Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp978208lqh; Fri, 29 Mar 2024 03:21:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUVrc1FyQaKNjSsFkD7I4z5wJq9IIlZPwq/o9p+LMR/WrS+Wp+0Tc/DVXTF0LA2XKLPTYqKpABoc2yyitSOjEFv6KKJko2cPWAVqEzr7A== X-Google-Smtp-Source: AGHT+IF11VEtyjbgQv0TbzeNEc/QspHUuBe99nMlGgAbUXCYNp0LG7B/6hkqDgPHblc4/VREwdcs X-Received: by 2002:a17:907:1115:b0:a46:ed72:6bb4 with SMTP id qu21-20020a170907111500b00a46ed726bb4mr1122667ejb.72.1711707679410; Fri, 29 Mar 2024 03:21:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711707679; cv=pass; d=google.com; s=arc-20160816; b=gXd8CP9tXmh398TSGYjjGiCfQq1/qLK1/fa8ZPYnEJBkhOP7So9U4XEmlYQb6kxcgG 9zWDrwU4zVz9S2wCFlNqbdzW2yYJjVSglcQ+0vu4Gif3uQsSNOTmKn1BV2dFBlcnIdSb vcBpAeoK6vhUnKRfs9apcIw57ELWYaotEjZcibP6NXacUVAGDycJmwdDYwUvvC14By5R w+3W3Jw3Z7TZcQaZ6ZSmSf3QexDNcokpEx3el6/ohs5mJfaqGQw2FezMKMoARR4e3TsZ JTZzjUUBkKRKTqFJ+20LkG/edrsXy++0IwMg/+NszYm0fvqD0Kb3FIipsPLl7Yd8H0VZ y1tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/F8gaERcalJx36nyC5MjGjkyvD0J+Hq79zQguhjOxdw=; fh=F8kIUlBuNLXktcDXFZXJsSxNFPlm5I4aZ+bFeqJfPRA=; b=miHH1zydSkexef4iawkdIfKUESOUMdWilurWgKPS6XFQbGePesngd1YjM08QD2lvit O8eccu5rsF9IoW1RIsyAY1K7r36eUsnt/uZ9tiRscRbR6UQjZ31+xXZwFWBWJ48WJe11 /R7MLWKfKJMVr3aXNx42QsU4BW6yqMV0ubatPssxj2t6kj+qN8Nkcc7NMY0PkOr3X9iN zGg+vtvoSwH2DRqNl38zpcQy1UpG8tWEWZS7bDveU+NB9FjbYdqoCxG/edXtUovUZN1D UTlQUj5zLiBWpvPdgDW5eNpZ964w0aWluFk9U63I23cPRqCRJikmiLYuWW+fIolxt+ab KuEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sZ5ny+kd; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-124382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124382-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x21-20020a170906b09500b00a46bdefb639si1660731ejy.382.2024.03.29.03.21.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 03:21:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sZ5ny+kd; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-124382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124382-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 251B91F232EE for ; Fri, 29 Mar 2024 10:21:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B50B53385; Fri, 29 Mar 2024 10:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sZ5ny+kd" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32E0552F7D; Fri, 29 Mar 2024 10:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711707670; cv=none; b=tlCXn55LxtHVB4jJF8MpEaOt/rlbjFmPfz8esKXATB4wgiD3fzKFTkNTITI1Z5iv3oa/Pn/+lPzppXiCLEuFta+XfnKoNhJlLuheSrfc59Tc8av/KeSsAne0r5XDTyqWDpXz+1W2aRIW/6gWKYg+OubpvFG8+6e0zfP3twweXEU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711707670; c=relaxed/simple; bh=FWV0RPdSwemXt+VGyB5/jZs/u/Zy2oHIfu++kCKBnr8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X0KUG/d+BxAnq4Lhth+7idCI6gvs2J2q+VNooI3uysZ0bRiBO7plNIAMrO8TcEVqQLS4yQJZFuhbfOCw5yI3WYm6YVoT4x6knXvwdOFyuRiXATnCdhe/lmrITmoayDxqyrLFL1QHptqjMOZ+hLisD5AGDcKFYBlcKO5RzbnEA9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sZ5ny+kd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B9AAC433C7; Fri, 29 Mar 2024 10:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1711707669; bh=FWV0RPdSwemXt+VGyB5/jZs/u/Zy2oHIfu++kCKBnr8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sZ5ny+kdCbNSKTKZyRo7jS/7rGT/lKqkbt9VoyfJzJ81aqlnbezfr4GPKClAdoCQu r4WZNLJDbodV83wSHMEHtB+nn2Q7pqWPjV7T0rsBWAFoV66t+CYik9ENgLLzLvQaWm bSUzjgpUtZ6cX0hPe6rd2jokvbGhw7nZfqg+RBh4= Date: Fri, 29 Mar 2024 11:21:06 +0100 From: Greg KH To: Nikhil V Cc: Charan Teja Kalla , Joerg Roedel , Will Deacon , Robin Murphy , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, stable@vger.kernel.org Subject: Re: [PATCH RESEND STABLE v6.1] iommu: Avoid races around default domain allocations Message-ID: <2024032955-exponent-nativity-fba4@gregkh> References: <2024030403-self-morality-062e@gregkh> <6dcf6bc5-e1e5-8388-8bcb-c093a5fb61ed@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6dcf6bc5-e1e5-8388-8bcb-c093a5fb61ed@quicinc.com> On Tue, Mar 05, 2024 at 01:01:12PM +0530, Nikhil V wrote: > > > On 3/4/2024 6:55 PM, Greg KH wrote: > > On Mon, Mar 04, 2024 at 04:40:50PM +0530, Nikhil V wrote: > > > From: Charan Teja Kalla > > > > > > This fix is applicable for LTS kernel, 6.1.y. In latest kernels, this race > > > issue is fixed by the patch series [1] and [2]. The right thing to do here > > > would have been propagating these changes from latest kernel to the stable > > > branch, 6.1.y. However, these changes seems too intrusive to be picked for > > > stable branches. Hence, the fix proposed can be taken as an alternative > > > instead of backporting the patch series. > > > [1] https://lore.kernel.org/all/0-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com/ > > > [2] https://lore.kernel.org/all/0-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.com/ > > > > > > Issue: > > > A race condition is observed when arm_smmu_device_probe and > > > modprobe of client devices happens in parallel. This results > > > in the allocation of a new default domain for the iommu group > > > even though it was previously allocated and the respective iova > > > domain(iovad) was initialized. However, for this newly allocated > > > default domain, iovad will not be initialized. As a result, for > > > devices requesting dma allocations, this uninitialized iovad will > > > be used, thereby causing NULL pointer dereference issue. > > > > > > Flow: > > > - During arm_smmu_device_probe, bus_iommu_probe() will be called > > > as part of iommu_device_register(). This results in the device probe, > > > __iommu_probe_device(). > > > > > > - When the modprobe of the client device happens in parallel, it > > > sets up the DMA configuration for the device using of_dma_configure_id(), > > > which inturn calls iommu_probe_device(). Later, default domain is > > > allocated and attached using iommu_alloc_default_domain() and > > > __iommu_attach_device() respectively. It then ends up initializing a > > > mapping domain(IOVA domain) and rcaches for the device via > > > arch_setup_dma_ops()->iommu_setup_dma_ops(). > > > > > > - Now, in the bus_iommu_probe() path, it again tries to allocate > > > a default domain via probe_alloc_default_domain(). This results in > > > allocating a new default domain(along with IOVA domain) via > > > __iommu_domain_alloc(). However, this newly allocated IOVA domain > > > will not be initialized. > > > > > > - Now, when the same client device tries dma allocations via > > > iommu_dma_alloc(), it ends up accessing the rcaches of the newly > > > allocated IOVA domain, which is not initialized. This results > > > into NULL pointer dereferencing. > > > > > > Fix this issue by adding a check in probe_alloc_default_domain() > > > to see if the iommu_group already has a default domain allocated > > > and initialized. > > > > > > Cc: # see patch description, fix applicable only for 6.1.y > > > Signed-off-by: Charan Teja Kalla > > > Co-developed-by: Nikhil V > > > Signed-off-by: Nikhil V > > > --- > > > drivers/iommu/iommu.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > Why RESEND? What happened to the first send? > > > > thanks, > > > > greg k-h > > > Hi Greg, > > There are no changes as such w.r.t first send, [1]. It is resent to gain > attention on this patch. Also, we have added a proper Cc: stable tag with > this patch. Thanks, now queued up. greg k-h