From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 AF5B522E407 for ; Wed, 15 Jan 2025 05:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736918794; cv=none; b=XWEqmJiznI4+xfUnd03He5rvm9G/g/XR113KO8XaECztMz1JNC6C61iYKDST/xBmgKBwsz3hWJlakhmTrlKwItum9WEDvDjHKOjoDwCRpoMeDsVlg4G7hP94yRwFAXQ984wyrN9Gwbplzkl2gHzTavAXmhi8p2foVuXP0ksfYg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736918794; c=relaxed/simple; bh=TJj4V68/oUvu4lGIMKGgm1DTMhGAomZC8D8xYI38ntI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a+eEEAMFKqNO73Ycag7O3IDgSJQBIowqlLlD4GcBt1NXoIEjTfAWpoMaQB7p+aTH/3hxSvnmoWsyAvAdHWCx3pFbtG5dg9udT6kNjZ6g6n9u8k7+j9xExEL5itzyI8p3IT2Neal1EM7qTRrknIW1Y/1HQgqzeNZaIHHsozIXaAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=JHMyEk2t; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JHMyEk2t" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-385ddcfc97bso5199839f8f.1 for ; Tue, 14 Jan 2025 21:26:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736918790; x=1737523590; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=twOTIQDMLptOniW9D3Ykrpwm4OwT+cQLeuqDgqx/bd8=; b=JHMyEk2tDLUBSiVsL8DGBrgq8RdyuurXd9hl/RAbnXkOygPE3Xce70RiCtKI5yz83e BmGL8OG4bYFQcrdpUNiRfTnNllyT3S09I1HuxQ628dv0mbuGUSRspIQFZ03fpwhskkw3 vOWHL/8w40AD2vYcuAhtvPqpcYa5CVkqlp+9nmoMD1LwuB/fMmnAFW70j0NAMrC0+Zwj LaH2wCxf6Dp5l2XDZcNZoKrx6K6VHEOhHjejhPChvcc2/xx0F3RS+GseWEHTzMOaSKZK ZCWtlt9UlKdyH/Izl4HXb+z34vhb3gT1wxtU9bH/TZaK/KFDt8LXdjI968C6YEPcnLRr /M4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736918790; x=1737523590; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=twOTIQDMLptOniW9D3Ykrpwm4OwT+cQLeuqDgqx/bd8=; b=jdUUzTBRy7yw0pOHoBUX73bExo9L2HqpluWjA9vPIZpeakQg9RMAIez1GHibhS/il+ p3gjz2P2ESUa5Bcyks2t4XAPj3LovNUVySm1D3qFDd7qSgjWoj7Z1pp0+WzA8LBUkINi Ngyt4KKeYr7wnJrfsnxKyfnt6NU3XYZxWLpmGx//k0wHSax6ZImXDvdEVP+1/b7CeRvA RRlUt/fn8YiKEaf2T9Wpf/afGjBPS7Ta+ITph8AVt/nh4djRvZnuB0Ovv75AfPD6YftT t1V+Yav4fYHb2u0lsC3QnOHe1jwkW3YtqVfKXr4yMdHu6CqujMGYPuuge+Ql26QEyONs j1iQ== X-Forwarded-Encrypted: i=1; AJvYcCUVeRSzJgT0+2cgoW1EgKzpeTMCm8gV0gum4sTv2CZWcgCg53QfjkR87G4mszqjaecbXOV7w59D0Grqptw=@vger.kernel.org X-Gm-Message-State: AOJu0YyOcunntWXq0q3oxoUiC9+Qt/kviXUgIljJIdbkC7dl6mAfBfT7 5gW0Eho3+9TtdQbLk79fR5RKN+RfJiqTyIXXZ89av3ZwDClnxvttmGopocUVQE4= X-Gm-Gg: ASbGncve5vNQtdPy1ObDFnITm+fDeOxIIld4kGbIiJR+eisr8qNNPb4LuFO3+B8rNXU 7UBouFFFyuki1TcIrpWZNN60TdZmiCp9cFf6LOhcr7P7sAR7gUMVpSOAwWWX7fSGx3fycOjRUAX m4l4FCQhZ/LP7/GXq+c51XpFjvIfY+nK5B9H/V97FmYId3j32u6MdpVmxvyWluN/O5SlInOY39p ZnfeygctX6r6cqVvGP6NlCKV1j5zVbF9jFjpLDFwNLpi1rf+mZA/W4MjlpbeQ== X-Google-Smtp-Source: AGHT+IH/vkacqNHuK2cXqcYAJ4HjIn/EgzODQtFuqUdC6bKz6TFDA/FAL5xJNa9BMmv2Q180MP7m/Q== X-Received: by 2002:a05:6000:1fac:b0:38a:3732:4462 with SMTP id ffacd0b85a97d-38a87317160mr27724590f8f.48.1736918789865; Tue, 14 Jan 2025 21:26:29 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c74c4f85sm10004785e9.18.2025.01.14.21.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 21:26:29 -0800 (PST) Date: Wed, 15 Jan 2025 08:26:25 +0300 From: Dan Carpenter To: Namjae Jeon Cc: Steve French , Sergey Senozhatsky , Tom Talpey , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH RESEND] ksmbd: fix integer overflows on 32 bit systems Message-ID: <20f85837-68b7-404f-9284-73597feb142e@stanley.mountain> References: <2fb3efb4-a889-4b49-8100-51147d9ae426@stanley.mountain> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jan 15, 2025 at 09:20:54AM +0900, Namjae Jeon wrote: > On Tue, Jan 14, 2025 at 7:18 PM Dan Carpenter wrote: > > > > On Tue, Jan 14, 2025 at 04:53:18PM +0900, Namjae Jeon wrote: > > > On Mon, Jan 13, 2025 at 3:17 PM Dan Carpenter wrote: > > > > > > > > On 32bit systems the addition operations in ipc_msg_alloc() can > > > > potentially overflow leading to memory corruption. Fix this using > > > > size_add() which will ensure that the invalid allocations do not succeed. > > > You previously said that memcpy overrun does not occur due to memory > > > allocation failure with SIZE_MAX. > > > > > > Would it be better to handle integer overflows as an error before > > > memory allocation? > > > > I mean we could do something like the below patch but I'd prefer to fix > > it this way. > > > > > And static checkers don't detect memcpy overrun by considering memory > > > allocation failure? > > > > How the struct_size()/array_size() kernel hardenning works is that if > > you pass in a too large value instead of wrapping to a small value, the > > math results in SIZE_MAX so the allocation will fail. We already handle > > allocation failures correctly so it's fine. > > > > The problem in this code is that on 32 bit systems if you chose a "sz" > > value which is (unsigned int)-4 then the kvzalloc() allocation will > > succeed but the buffer will be 4 bytes smaller than intended and the > > "msg->sz = sz;" assignment will corrupt memory. > > > > Anyway, here is how the patch could look like with bounds checking instead > > of size_add(). We could fancy it up a bit, but I don't like fancy math. > Okay, There was a macro for max ipc payload size, So I have changed > INT_MAX to KSMBD_IPC_MAX_PAYLOAD. Nice. I didn't know. Thanks! regards, dan carpenter