Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1664431lqo; Sat, 18 May 2024 13:22:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWOsTOPFHZd9RxFBPfAGZrzsG6jkmzBWNedhAafMxtUOmSC2H/rMolNKs7pGvnLGw6wBBToAJvmRMhvyjvqh9Ue1073z9+QQ70N2dHHA== X-Google-Smtp-Source: AGHT+IGR3kXHzeL/zBFUCdv5EpK0SDUWalsKOuQs8pxGRZ4W73ww4p7dADsnph40vJCZlF9wwbe+ X-Received: by 2002:a17:90a:5505:b0:2af:9e88:d41d with SMTP id 98e67ed59e1d1-2b6cc7804e1mr24671202a91.23.1716063726180; Sat, 18 May 2024 13:22:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716063726; cv=pass; d=google.com; s=arc-20160816; b=q8wpSxOMGP8ENNCN3PqzsWV7TLAZF/gMa2hoqOBsT6B8xHpphFITQIGvlrpltqzKBB JaeDlFknCMTjQeuGDGlZ0y4vxmRLlr2o+BhUgHJLHzyTo3zOweey/BIOlv3O934b+kGT /j3HP39HPtjxsgyoUNBQYDDN9E303OkTOBDu6yRvW4H2QweGuxtfqmFlK+iuU9o5Zexe azWeMCS53v/LP6SOVlllEvm2LEUwKZa8W9vhGhDbMFFX9TNEGBtXrDZ6fsDSWeKv1i/9 QQ4Wbzz05GEWBoD9LL5lbBS0MB7hLvnmDwr21VvTlds+C5VBPVGBlaXD3s79CvfC2jqb mvng== 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=YT8k8s66KczJAsNizHEAZ30DCNByiIsnyYkGU9dE27E=; fh=5zZmakNFTVyapnEAPQprL9G6/cehhiVpwyhRefi5a3I=; b=Do9dJa0UdqGBl39dDU2Qd/fUtg1PBv+tKxNCW8yWoniU9k6r5MBjdLmEGjvkPbyb1I 1UGq0G8LJUV1VXsDmTc1XuDIC/NFrJ4OSyNmHtZgyz6xurmwY9I4eGJNJULS5UTnGRB3 Ek8RJHyX5f0sQN1gZrEyIRoN6/G5yM0MxPupQ8bVpUKa/m0XaGitGcg5nf7hHRjz5DDh RUpJ7blQ1ZnlP55g5e4cuwcloxG0TBKK3e2g2NqTcXjKaoEZI0biyAJKRNZxV1dlpzoh kT2TSQeC9P7Xlphaqv10jiXW4UlCnFjVREu/wr53hvZu+9uLN41/oCwH06G7muRtUsBb SZpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YOCpMiKG; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-182955-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b671471a10si1700163a91.90.2024.05.18.13.22.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 May 2024 13:22:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182955-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YOCpMiKG; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-182955-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C83E1281AB4 for ; Sat, 18 May 2024 20:22:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6CE3626DF; Sat, 18 May 2024 20:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YOCpMiKG" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 5C5E160DCF for ; Sat, 18 May 2024 20:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716063719; cv=none; b=cO5b3jeSSZnsquR3G9NIWVgB6WmL6l9wUf+JuRfzQX26UQMa096xXo8mKhmy0AUCwmcf5wd5hklzHdURU7TDv/zfbIdhu+A97XeqiDMmBru7BRlxlCHBGQLn9ZcomGFFBxba0CfPREUvC6vwmF6psgQ+n3z7P+YCtW7YceLFQ+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716063719; c=relaxed/simple; bh=TIqCDYP/WZC+8WCV9T+fsdqDELqSHjVL9UHHO59Pw7o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iuo4IYVDlZeYaNgiDgKF+T7Iy15fQAyAO3glhxUCVO8ure5uZVfZqSgm+cQnZb6Oh//mef4XPftK8qzj6bYO7/fH1PTrmhzpS4o/N4gbhMPnkRwKWmeouDUVYvwUC4jrxcdT273iryP0GbsyTuSPVnpxxF8H8IwHWaLcQThpXqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=YOCpMiKG; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f2f566a7c7so9630685ad.1 for ; Sat, 18 May 2024 13:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716063718; x=1716668518; 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=YT8k8s66KczJAsNizHEAZ30DCNByiIsnyYkGU9dE27E=; b=YOCpMiKGoCagxA9Q/d+T7HVa9JcZI6hSymcYBNgQeJ1hgvDOaKD4ckeCBP9v5krCNZ EQ4IIAkZadRIgoKxxIdFsYCFcf5SC2OI0NhoC5SpZsNYgsk6TjeFFFRmmeBNfOLnnNeq 4GHfKNue0RDwNI8mXRxWNaZ0NxgHxL3pnPID8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716063718; x=1716668518; h=in-reply-to: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=YT8k8s66KczJAsNizHEAZ30DCNByiIsnyYkGU9dE27E=; b=W9bXS3+IpZhIkqWvtwmWri9mrDYJAYePlG6H/3QH/sg9OuhvamJZ25y2lHIVf+N0CE PLGPdyuV83jj7EhHBEA1w2aFfLcjxMI4rFA1j0r7apOk2MlZKzU7OVuDmBlj+t7CZWEV fnZinyEmloRzMZytG13CIXLJEdCtG6h5nSTbsf4ref8DSGRsJy7bzoGxRseYNEQRpOgs oBHILwI3Le6Agdd02Yzah6tY9U3u0cs6VyjGA8PtpixtZSIjuONDn3eUE+Q+vTvOxtf3 5z2OFhi0OdP1O17RWRP0ka+k54VRwSf5YgUxVV8iYm+7VnobORKW0lIvcTBCbJGE8kMD 6LfQ== X-Forwarded-Encrypted: i=1; AJvYcCVagmfu08AneEKoXzStP4wPJoZ3ir0i66aplfHF7RFEcYKVhjSvIbIsdPEmbxwqJh0vxTbTsAfELzRYH80cpw4iA0//DzvkyGPm96Uk X-Gm-Message-State: AOJu0YxADZ4burVnEDm88mXOW5IrHUWgmhlw/4WGXoTyqG+G7awghU+5 aZ/woDKgDgi/M12J6QI+p6Rni1IBg8Jp/Zz+jE2GTDb12V3BiuNHXeTkS3ZT9g== X-Received: by 2002:a17:902:f705:b0:1ee:b47e:7085 with SMTP id d9443c01a7336-1ef43c0c957mr310157785ad.12.1716063717708; Sat, 18 May 2024 13:21:57 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bad61c7sm177715425ad.68.2024.05.18.13.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 May 2024 13:21:56 -0700 (PDT) Date: Sat, 18 May 2024 13:21:55 -0700 From: Kees Cook To: Guenter Roeck Cc: David Airlie , Karol Herbst , Lyude Paul , Daniel Vetter , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Javier Martinez Canillas , Jani Nikula , Thomas Zimmermann , Danilo Krummrich , Maxime Ripard , Christophe JAILLET Subject: Re: [PATCH v2] drm/nouveau/nvif: Avoid build error due to potential integer overflows Message-ID: <202405181321.BE7CB28587@keescook> References: <20240518182923.1217111-1-linux@roeck-us.net> 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: <20240518182923.1217111-1-linux@roeck-us.net> On Sat, May 18, 2024 at 11:29:23AM -0700, Guenter Roeck wrote: > Trying to build parisc:allmodconfig with gcc 12.x or later results > in the following build error. > > drivers/gpu/drm/nouveau/nvif/object.c: In function 'nvif_object_mthd': > drivers/gpu/drm/nouveau/nvif/object.c:161:9: error: > 'memcpy' accessing 4294967264 or more bytes at offsets 0 and 32 overlaps 6442450881 bytes at offset -2147483617 [-Werror=restrict] > 161 | memcpy(data, args->mthd.data, size); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/gpu/drm/nouveau/nvif/object.c: In function 'nvif_object_ctor': > drivers/gpu/drm/nouveau/nvif/object.c:298:17: error: > 'memcpy' accessing 4294967240 or more bytes at offsets 0 and 56 overlaps 6442450833 bytes at offset -2147483593 [-Werror=restrict] > 298 | memcpy(data, args->new.data, size); > > gcc assumes that 'sizeof(*args) + size' can overflow, which would result > in the problem. > > The problem is not new, only it is now no longer a warning but an error > since W=1 has been enabled for the drm subsystem and since Werror is > enabled for test builds. > > Rearrange arithmetic and use check_add_overflow() for validating the > allocation size to avoid the overflow. > > Fixes: a61ddb4393ad ("drm: enable (most) W=1 warnings by default across the subsystem") > Cc: Javier Martinez Canillas > Cc: Jani Nikula > Cc: Thomas Zimmermann > Cc: Danilo Krummrich > Cc: Maxime Ripard > Cc: Kees Cook > Cc: Christophe JAILLET > Signed-off-by: Guenter Roeck Yeah, looks good to me. Thanks! Reviewed-by: Kees Cook -- Kees Cook