From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 A1ABE2F25F3 for ; Tue, 28 Jul 2026 15:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785252647; cv=none; b=o5eNh/Qm5PlBJ2GCDlZ+sMjRrKbCbR7W4ql7s53AAohAAS33bV23Nzf5I/tyZyMiS//ZzlGe1NBlSRyM2z4f9exu7x9p8oUZOFRGEIS1n4Zcuc5DWtvm/OdWFXlJdaqXSrCvWJ+2/+SkQ1azAfqs8ysCohASy12C8P4z6ZV2GWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785252647; c=relaxed/simple; bh=E3k2KFJC5Kpsm6RrzIJ+HVsT6arOOMIj3f9XyiLwGyY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PMydv379C9UfKGPxptCdygfRwmizrSWSSn3hgOq6gPuPMPLckj9/8hsVMYjmk80dnE6E30vb1WINptrB37Wf/ThaaB98NV7tssXzfSvbCQcH1O5x9mBDh7Zju6tFqjV8bbwvbiv6jQ4KaXRz47gJks2C1B0stDiwciX1Ju6cInI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dama.to; spf=none smtp.mailfrom=dama.to; dkim=pass (2048-bit key) header.d=dama-to.20251104.gappssmtp.com header.i=@dama-to.20251104.gappssmtp.com header.b=MOQJzMkL; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dama.to Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=dama.to Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dama-to.20251104.gappssmtp.com header.i=@dama-to.20251104.gappssmtp.com header.b="MOQJzMkL" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-8453427d3f4so4138977b3a.3 for ; Tue, 28 Jul 2026 08:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dama-to.20251104.gappssmtp.com; s=20251104; t=1785252645; x=1785857445; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8kJyeGI8L3V0IAqYou544rNxKptwzjPjr8r5SGNglkM=; b=MOQJzMkLcKqrN0aNJH7XYAA7PymXldiiuXlPo6OVg14vr8+rUaUy7Bxrnl9hBcv1bP 4351/yu19Zqj8OklMRiSydsCEruBurFLKMng8DjCzo/jEGmd4kV1DFT71jq2e0rGVvOc FrDrrlz022NbHzGSgBsZUPpGhO1nQlD5PvwwYbOWDwI+mEffkkAbXEHYR7BsGvrF7krk uqM2nIfZ7XPJUhQvoApMdNWtuz0LI2A4RA/XIL8RJe2DSr46wotRq1IsCufijtqBoiHV UNr36Iic5Rcr3KcZaIwRu+UeNbMW+JDQruoAdiN8I31gQfLYCU0D/yUT+BteVZJHo7Ec ASZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785252645; x=1785857445; h=in-reply-to:content-disposition:content-type:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=8kJyeGI8L3V0IAqYou544rNxKptwzjPjr8r5SGNglkM=; b=TdU4soqPHrgPKMnnQv1OKX3kfYs4KHCCJpDkw0cab04uqVZAI2doF4IaS7pTSy8Z2i Wg1sv8a6kNwl1LYjE6aF5LVduhtGVLUn75JM/JkiwjGC2e1z96O0C+o7bQIhPvsxncD0 zyeEfw32LBannZ8b4m5iSkg3Uq7DqjPQFQj4wYJenF7syINqPwFJmH1KiZ2wK8fEsE2y r9ccJtzLk2qJG1tXCM3HEntlSub3wWySbW5nEtnONJQETVWPurthKMijU1/ikd+Zlsf3 sFkef8Ya3r1mF7QIq/Plt2NPpTOyh+CuQxnoIb5O3SffA2dsaViRwce2fcg6S27o3Xho 534w== X-Forwarded-Encrypted: i=1; AHgh+RpAPPr32FK+04t1Sqb5W0+Q5UOJ6SN3s2ktUcEaOM8W2B3+D0A38i+DioyLiBgoKYS4ue0F56AwpYu3zkE=@vger.kernel.org X-Gm-Message-State: AOJu0YzejL5LQcnsXt1J69DeeKu5H9jqICTcbH64yH+nYMNqtg3+gcPY tZY2sgnnDVYphXbZbH65VB6QysVanOhX2iJ7blKHfIoejvfMvPHvFudYT+62pubxfDU= X-Gm-Gg: AR+sD10iCeNhvy9C/zcmKxeH4gDR9F4Vzo8B82dFD5FT155c7gyUzkE+YyHTzciyysN Rak/j4u+/I2a+nCTVSPN+3sq+doh0qdah608ZLaKuGuJXrYngSa7ZDFT8t8gE0ltNRFJKRlw1Rg Z/4+Dw/gS5Yt9bicwCttIxeWGVeGoJgDipGOX6PL643lbuHPi3wqheO4N4+XZBsscalyBO9pLj8 9xcIb/g9go01XPQCPTgbNPMg12J+5M83EK25DVm0EnxLyBSwME9rpOn+tFtZ8OyPWLktF+4ngJn J2SDjqDVEqbQ++MBY+4R6y+5EZXzJH8Q0U6+y6+CXBUQ3jQ+gYlNDUPlJiWoRXLGhjXu2VEptgE fCot9xElaqCUuowHQQ03ZD9hvYDQ0UjEV0uLUqrOEI6ggc/QS50hgqP6ltm4= X-Received: by 2002:a05:6a00:4c8d:b0:848:8715:c2cd with SMTP id d2e1a72fcca58-84e933add88mr3388843b3a.47.1785252644148; Tue, 28 Jul 2026 08:30:44 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:40::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84ea0301b3csm97521b3a.34.2026.07.28.08.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 08:30:43 -0700 (PDT) Date: Tue, 28 Jul 2026 08:30:42 -0700 From: Joe Damato To: Jiangshan Yi Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, stefanha@redhat.com, mst@redhat.com, will@kernel.org, ralf@mandelbit.com, viro@zeniv.linux.org.uk, kuniyu@google.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, 13667453960@163.com, stable@vger.kernel.org Subject: Re: [PATCH] net: datagram: fix integer overflow in zerocopy_sg_from_iter Message-ID: Mail-Followup-To: Joe Damato , Jiangshan Yi , davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, stefanha@redhat.com, mst@redhat.com, will@kernel.org, ralf@mandelbit.com, viro@zeniv.linux.org.uk, kuniyu@google.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, 13667453960@163.com, stable@vger.kernel.org References: <20260728064235.337877-1-yijiangshan@kylinos.cn> 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: <20260728064235.337877-1-yijiangshan@kylinos.cn> On Tue, Jul 28, 2026 at 02:42:35PM +0800, Jiangshan Yi wrote: > zerocopy_sg_from_iter() computes the copy length as: > > copy = min_t(int, skb_headlen(skb), iov_iter_count(from)); > > iov_iter_count() returns size_t. When it exceeds INT_MAX (e.g. via > io_uring provided buffers), the int cast wraps negative, wins the min() idk I looked at the code and it looks to be capped at INT_MAX, so i'm not sure that the io_uring example could ever happen ? I think the commit message misstates what is actually possible > comparison, and the negative copy propagates into > skb_copy_datagram_from_iter(), which can trigger WARN_ON or corrupt > data. > > Use min_t(size_t, ...) so the comparison is done in the correct type. > The result is always <= skb_headlen(skb), which fits in int. > Fixes: 3a654f975bf9 ("new helpers: skb_copy_datagram_from_iter() and zerocopy_sg_from_iter()") > Cc: stable@vger.kernel.org > Signed-off-by: Jiangshan Yi > --- > net/core/datagram.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/core/datagram.c b/net/core/datagram.c > index c285c6465923..fd8e17d25a3d 100644 > --- a/net/core/datagram.c > +++ b/net/core/datagram.c > @@ -783,7 +783,7 @@ EXPORT_SYMBOL(__zerocopy_sg_from_iter); > */ > int zerocopy_sg_from_iter(struct sk_buff *skb, struct iov_iter *from) > { > - int copy = min_t(int, skb_headlen(skb), iov_iter_count(from)); > + int copy = min_t(size_t, skb_headlen(skb), iov_iter_count(from)); I don't get this. Wouldn't copy need to also be a size_t to be consistent with the general "idea" of this patch ? If you leave copy as an int aren't you just shifting the alleged overflow to the assignment ? Even if you changed copy to a size_t then..... > > /* copy up to skb headlen */ > if (skb_copy_datagram_from_iter(skb, 0, from, copy)) this would still be a problem because len here is an int ? I feel like if you really wanna fix this you would have to use min3 or something instead of min_t ? But, I'd probably just leave it and not propose a patch to change this at all.