From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B8BF23D2A3 for ; Wed, 26 Nov 2025 18:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764180075; cv=none; b=IPbTauG4Z/QHmO37Y/Kks2PQhj0PX6d191yMzuG+8ZOK5cC8eCTy4yGovp6BJ/U8rXvZ22Eq1kLSiVV72gBnbpWO4Y0A1nW4ZS/6LNM5IOrO6bURuKtrBMrbiJdY+jPAWlBnSiD8VaqeU7oxr2C2qlAXm25PErmMnv2vifX96m0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764180075; c=relaxed/simple; bh=O8Oxlh3txsqOf2IumAFDD74EyC3t+dmObTYw1aRFmW0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VYUYYQZ77MynTNlIkI44r2TQGJtSU7VeuT4Fsw/TAvBtiVB0vhrSSSXc3YOIbTXH1v03UXPqm9C3zCarKjZytvbzdZqGPY3YLmLeK+GBPApB+3mZzKTMXl5XJvX1XrGSGROF0poQp3z0CUCKyEZM/LMri7tH+4ybeInrKaE35Xo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=ZUwQHn7i; arc=none smtp.client-ip=209.85.219.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="ZUwQHn7i" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-8823e39c581so66166d6.3 for ; Wed, 26 Nov 2025 10:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1764180071; x=1764784871; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jjSf74md9hV6abcmJUmAPy1uC1ZA/qAadY295f9z6us=; b=ZUwQHn7iTD9H3QuCokh18ubvXS3pH4A1pReeV6g2okuBMltvX44Fxh0LxVVDfWQ/Cs 2XrZ6Gf7uZoaYTspqeMUqqb4uWaHYdIKhTXizH005ui/hshdBAqyg7piHiB9QGKiRbOc baTNwmbSM16cto+rEhKElMTUsvcl6fsanzXDXQ+CzH7M4FuWYjRs7PbL6iwVWPOS7dTo 9SE5qAIQ8yrFwVBWGuD4lZJSa5hYrx5/Ahl519RKURIWGmYsiOLosBsv0dgRMCzTrfSW tQsR08K+YUH3kReWnFS79k73sdT1Pf1NcF4rh5nk9MKW52hrNy0cAJC2WUEH3ZYXsoyB WRug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764180071; x=1764784871; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jjSf74md9hV6abcmJUmAPy1uC1ZA/qAadY295f9z6us=; b=vHW880ybAvSF8rBnCIr/BDqubiJ7w1zudawpmPo9SEgR8h9a9B3HKbMvZjW+ZynBk+ mIm5ytu77rVdhla+P7GD2xWNA039Aiz0nMXD7l50DsomyiMxqkrc+Zt+/f+BJf1Y/dlJ 7djzA6kDBOgxUiPAK+y7jDY/yrntWawUcCGRmG0a/RbZk4CBiTBhiAVDkFX7zsRpc9pp 5RvJxxkR/SIS1/Zwevqg4DqFdVS1AS90ksJ8ylz0jNlW+jSb35EWRbyKVYg/FC1n1XWL T0p1RK59Vvl3nKcznWAI1vPx2aM+D5DxHZr6jQSypayGRT7G5RZCk/CqR0RPJbg5CSoy 7VBA== X-Forwarded-Encrypted: i=1; AJvYcCW5RWdC/MFE5HEtMVeAfrQg8z8tFQeJN5NvFh8kK+HplXAhmj1gkohbWjmk4L+B2kuTYjLRljcVzvjuGDo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx60K67EU4Dq1aIUomADBVjY5KwBwEfdP/Vj8IvIrV41+6lhu1V vJk9t3s5Gzl1UlehP4Q9Ae8I3UJRidInz1XBEqJHhXy8citUeQf7wBuOYn4KMQ0g+3A= X-Gm-Gg: ASbGncsXeXgXzYVjyCKSD0Wa84p9JohryI7yijpirWXtHHv0lULO8IEDpCssKvdzanc QaZdbw5mzxq1cjTFWPlQjMVXT3TBgAaAknkn4QWuChwaboQygcCZCS9lKtt+bCI8BQbOYL+aKJL 8JEugXD3sarSB7OUjLoaEtaMQa9o5garRkYEGc0C/kfCVfz3NcWIkgDK4cqHLJXT8YFbDyiT6kY MZ+7j9elvzmaGeiw9WLHhYoUVRCaYAMp8oHXPqKcjKVe0o3ZQcAWSh24rACba7jTyJ+ydeo/Pd5 wIrFF8NEydHMmg6Bx4uEZJBGQdQxxIwB0F5S5Y/oG57UJKxt+iwpF1XctwqkH7JJ0YC1Bxt03hB jjpnmTW9AVSFjV+z4qgKviIK3kh0yd+nnsJLwIk0Z0iwedcFrCRCwkzHd6S6NZDviGLkoxwMkWo pMO1sgSAswMS+4xsQ5HMeirVnlM2m18pF0kim+2IcvsM4E4C03iH1vByEI X-Google-Smtp-Source: AGHT+IEAvNp+zRI8SnZtBMAoTCcW9PsOn0UFKbLCX0nJH/mWJ9Vruy3K7nib32RLaHWbWg9aiKoVNw== X-Received: by 2002:a05:6214:3113:b0:882:36d3:2c60 with SMTP id 6a1803df08f44-8847c4ccefamr223992386d6.19.1764180069440; Wed, 26 Nov 2025 10:01:09 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-47-55-120-4.dhcp-dynamic.fibreop.ns.bellaliant.net. [47.55.120.4]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447272sm148376376d6.5.2025.11.26.10.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 10:01:08 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1vOJpD-000000033ob-2pNk; Wed, 26 Nov 2025 14:01:07 -0400 Date: Wed, 26 Nov 2025 14:01:07 -0400 From: Jason Gunthorpe To: Alex Mastro , Alex Williamson Cc: Sumit Semwal , Christian =?utf-8?B?S8O2bmln?= , Leon Romanovsky , Kevin Tian , Nicolin Chen , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Ankit Agrawal Subject: Re: [PATCH] dma-buf: fix integer overflow in fill_sg_entry() for buffers >= 8GiB Message-ID: <20251126180107.GA542915@ziepe.ca> References: <20251125-dma-buf-overflow-v1-1-b70ea1e6c4ba@fb.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: <20251125-dma-buf-overflow-v1-1-b70ea1e6c4ba@fb.com> On Tue, Nov 25, 2025 at 05:11:18PM -0800, Alex Mastro wrote: > fill_sg_entry() splits large DMA buffers into multiple scatter-gather > entries, each holding up to UINT_MAX bytes. When calculating the DMA > address for entries beyond the second one, the expression (i * UINT_MAX) > causes integer overflow due to 32-bit arithmetic. > > This manifests when the input arg length >= 8 GiB results in looping for > i >= 2. > > Fix by casting i to dma_addr_t before multiplication. > > Fixes: 3aa31a8bb11e ("dma-buf: provide phys_vec to scatter-gather mapping routine") > Signed-off-by: Alex Mastro > --- > More color about how I discovered this in [1] for the commit at [2]: > > [1] https://lore.kernel.org/all/aSZHO6otK0Heh+Qj@devgpu015.cco6.facebook.com > [2] https://lore.kernel.org/all/20251120-dmabuf-vfio-v9-6-d7f71607f371@nvidia.com > --- > drivers/dma-buf/dma-buf-mapping.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Jason Gunthorpe AlexW, can you pick this up? Thanks, Jason