Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1969392lqo; Sun, 19 May 2024 07:10:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5R6zl0FTk5Ee+ubPoGbqW5Gzbhje0QUFvr50SiDkxw8zg+gWbnYaxU3f5qYLBv7hYQXO8FK53NZfaBTl3Z652tCeYuvWgtJUJZHXcxA== X-Google-Smtp-Source: AGHT+IG3i/FKAptPuYucHTMYXVtg8eM4ARKDLV8JMz22LeeJlsZJI00G42od8XnyCC1hLCOY7hbe X-Received: by 2002:a05:6a00:845:b0:6ed:7684:484b with SMTP id d2e1a72fcca58-6f4e0359ecfmr27986902b3a.27.1716127802632; Sun, 19 May 2024 07:10:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716127802; cv=pass; d=google.com; s=arc-20160816; b=AD938KeYV0KhnPna6p49E7ZhdpIcgLGxlEKBaVU3bTDuilp8S23/UdxcB8YtHuTGa8 rUSV31zBASSROYiEfxEwnIxsn65Hwc4kETLUobyZ5+vOlG6H/hqXmMgpkXqb+i/TABx+ WGULCxYPojA8K23PKpvkpf0ZrREAb+GlX/PkEzhPQVBPmvwk1rPfFydoFRo4MrIIIsyG 4zeCqSWriA9s9jsKKdmL8/lPuYsR9gNScir/Hrd8DJGM46Pky0U55qi4OdDfdOmbyRFU cqXfBV3DlGmUDJftM3gKNC4pfDGr9dw2ORDRTJkTOFWkuZxsi59HeGNwV4vKVEwR8sIz n/Ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :sender:dkim-signature; bh=vtcnP5ITObrTkigttHDPw7YJgxN6MDR2Zkm+Z0h4/Ew=; fh=vFi93vrr0L/lr39Ukss/6vxppgKW1rDsPeA/flEDk7s=; b=lSpSHpmi3+eEx2tQlE7REq7zJG07yaWZGupqtcZRl0YM/j6tP/hNumkpHlomdaTwFu c+VRrEzs0iJR6mEfoOAtiYhMS5wykSL9HydKQ8RcHuSC2BPXRs7BTnWZDnKgGIsPaW2F uBp7bgJtsfekOmxxdQUQAX301BlcgiiJJySMqyPe4M+XnKwPortG59vAPGzMDSXQXxEO V0KXUruud50PmtT4+YGkZMdm8Mqry+1+jiKEMZLH8cVEApJ+heaxdna98NtIQNRQLhCz V7XgOCjSXMPi5t0iXZjOhHciTxbLBn1/DxscLSAQriJOdfvG2tBunWBs1hzIl/l3iTHU 96lw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XOsr2k92; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-183120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183120-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2b170aasi1182490b3a.244.2024.05.19.07.10.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 07:10:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XOsr2k92; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-183120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183120-linux.lists.archive=gmail.com@vger.kernel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C8D34B2126B for ; Sun, 19 May 2024 14:09:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17B60487B0; Sun, 19 May 2024 14:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XOsr2k92" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 7C74D1A2C10; Sun, 19 May 2024 14:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716127790; cv=none; b=PV63xlz9/paJyLCN1AtGIJDuFR7Cg8RurS1k9NCueKG+t/cqNqUsJLq+zZTV4a/AtlsrtAt+RgwZ3IcOICXo+yze8dIgWz0fKvtXWzBTaXAmvLFFiTSaQxfUEwibKspum9bh7GX5iravq42ae2VFRRkPVzGOd3rK8lVzcSNxMn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716127790; c=relaxed/simple; bh=HjuiFlQQFdsUeatYqfwjvKGG+Huf8kQRDSR9L/f9aYI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=a8M1ftceU7euArII513tqpNiNcVUfxA0yS8Ud6p64+jHx7hbOauUzfYtjla83Vm+SrSMqSuVAYjLWXCdK7AFN2pNgetSvznxSOEU28s/lQDr8BIIVJ6lmm7cMfwhkh/x6q/DcLUz4AMEvxRph32mkjYTq0Sn+hzbf38p6defhog= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XOsr2k92; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1ed904c2280so43345435ad.2; Sun, 19 May 2024 07:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716127788; x=1716732588; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:from:to:cc:subject:date:message-id:reply-to; bh=vtcnP5ITObrTkigttHDPw7YJgxN6MDR2Zkm+Z0h4/Ew=; b=XOsr2k92hjl7Cqtn81BBMbVWl7KVIhg+yDC//wBTGdx7ZjHiItAAE/JRMsSv8CqcTH ITDe7bgQ1cjYdptmaC2iItp9l7XCsyFSnwBo5rrPUjGe2r1kI7JkWqeRN9lAhUzVihGV Cx7PhZ1yfh/9ff4mcqejS0OmU68JNPc4UHlIEUTelvHxCsfpRb6Lv8bK9QtC34UMoF4U /0mmrIexeBKEEVtO21SDMm4NrNwyCHrAwXLMSqpuuyp2Id8rnWVMzL6uS/AUgSuU897y qV12wwy3WAqiEJg1hVnZV0B+1IUjHddxzEy11ThSIq0d8YN83YAVZYWwgq+Mioeng0+c eeDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716127788; x=1716732588; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vtcnP5ITObrTkigttHDPw7YJgxN6MDR2Zkm+Z0h4/Ew=; b=EkZ4FSTEy+AxhQA5d6A0J4CywAvQy/KKPh4rcJsb0gN9jyPDeQHcN2ZR8sXsfpeQ26 D14BNjuwD6Lziq5RfNh3PLTdUn+6JhzBUx9uNV11mJ+/PeFrkpstBNdjqtPBy4zb5Pz4 trWBKKKgpNx+IhifE7IMLN3vfh3qdOzZew25dj//cLgsngXuutB125njSsYHiFT1DW+g FDQjlP4qspGLfi2Pr40df8EkDYBOeToPg91J8Sgryd48+Ay/nuTbe7YAwSUWpageq+tu Kz+DUFQSR9JRV/2Ov0Ap9LO2xfcH4IaiHAloQSpXAEvN8bWoVsQ2hg4Q7MSETlWjsqis w6nw== X-Forwarded-Encrypted: i=1; AJvYcCXt3rRwZqMY3TuNuI4i4w1Fy5dWkTiq9g3EkTnpsdi/gdVJ7mEg3GN5mzGWu8BkB/CFnyNcfynQ+RouGOnWnV2sbA8xOcBHeC1Vnc1vARaEVm4I9ijNl6qbpVFeEnH9b3vPO5XL4uiU2h1AlkSN X-Gm-Message-State: AOJu0YzKfXeTRMQYrk0plySfxMA6fO7tvuFhuULwd+JCP3WQ5F9fSC47 YWbCitybtECq476zejng08fhudbAQ0wVFRuWgGPSaD3TtlsC7Zgq X-Received: by 2002:a17:902:9047:b0:1e9:320c:2ecf with SMTP id d9443c01a7336-1ef43d2eeefmr244624075ad.35.1716127787597; Sun, 19 May 2024 07:09:47 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:329c:23ff:fee3:9d7c? ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f0f192db3dsm64422115ad.233.2024.05.19.07.09.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 May 2024 07:09:46 -0700 (PDT) Sender: Guenter Roeck Message-ID: Date: Sun, 19 May 2024 07:09:44 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/nouveau/nvif: Avoid build error due to potential integer overflows To: Joe Perches , Kees Cook , Christophe JAILLET Cc: airlied@gmail.com, dakr@redhat.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, jani.nikula@intel.com, javierm@redhat.com, kherbst@redhat.com, linux-kernel@vger.kernel.org, lyude@redhat.com, mripard@kernel.org, nouveau@lists.freedesktop.org, tzimmermann@suse.de, linux-hardening@vger.kernel.org References: <20240518143743.313872-1-linux@roeck-us.net> <34a6d812-b4ed-4465-b0ec-e641d185b9b1@wanadoo.fr> <202405181020.2D0A364F@keescook> <03cc262da2a3db817aa5663fbce6c914708b74f8.camel@perches.com> Content-Language: en-US From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+h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ZtrhLuLjHRCaG50OOm0hwPSk1J64R8O3HjSLdertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= In-Reply-To: <03cc262da2a3db817aa5663fbce6c914708b74f8.camel@perches.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/18/24 18:19, Joe Perches wrote: > On Sat, 2024-05-18 at 11:23 -0700, Guenter Roeck wrote: >> On 5/18/24 10:32, Kees Cook wrote: >> > [] >>> I think the INT_MAX test is actually better in this case because >>> nvif_object_ioctl()'s size argument is u32: >>> >>> ret = nvif_object_ioctl(object, args, sizeof(*args) + size, NULL); >>> ^^^^^^^^^^^^^^^^^^^^ >>> >>> So that could wrap around, even though the allocation may not. >>> >>> Better yet, since "sizeof(*args) + size" is repeated 3 times in the >>> function, I'd recommend: >>> >>> ... >>> u32 args_size; >>> >>> if (check_add_overflow(sizeof(*args), size, &args_size)) >>> return -ENOMEM; >>> if (args_size > sizeof(stack)) { >>> if (!(args = kmalloc(args_size, GFP_KERNEL))) > > trivia: > > More typical kernel style would use separate alloc and test > > args = kmalloc(args_size, GFP_KERNEL); > if (!args) > Sure, I can do that as well. I'll wait a couple of days though before sending v3 in case there are more change requests. Guenter