Received: by 2002:ab2:5182:0:b0:1f4:61d5:3ad4 with SMTP id x2csp57630lqi; Fri, 5 Apr 2024 09:37:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLW2QtLDbIPjimpENpevq9MC5VIuWbXNB5fBVyAPueK7pZiDYbrcyEgmlST0fJ+H4lv5XJQrg8tTFVxb+8V129Yzf5TPNEzpndLSF1UA== X-Google-Smtp-Source: AGHT+IE7adVVBneqUAVXKe9Qu+jqJuFrA9xgQ393dgtIiENnioapWen1Ye7HD9LlJKzgullzIrID X-Received: by 2002:a05:6102:390c:b0:479:e2b8:18e9 with SMTP id e12-20020a056102390c00b00479e2b818e9mr1387717vsu.30.1712335069930; Fri, 05 Apr 2024 09:37:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712335069; cv=pass; d=google.com; s=arc-20160816; b=HgkK4yiBQpPLveYMnQQufPYc22en/iFcSjesC1zsXKU1RZz7PzRlqG0/Zcl3C5mF1v ijIW+POf164U/RX83gIcqBO1QxaWPWzVQxzJUu8/xl6PEQbcRfWa6QbwlQAbWY36GBVn 48nUheGnGo/itpV/61bnUUeeKUSvkI+Z3V83FxFdiGOREF8ray/RMJpYtgY/2E5zcSfA j8V4kIUcEQnf4EFCt+VhGDeAf5LyJX889T7r9kZ9mDBL0CQL8hQP3UIE63hpWCEzm6p6 euWQTyyqnekd7CPOrf2BibjoYiMbZjf+BWVI++LAvHdrIfDhSOeCMFKgCpj0KiA1hj1x 5XGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=HhqXEsjcQfRnbT+Watd5B6B0qa6OPofOH0VzzxL2RKw=; fh=nq+Wb7NWELf/lFumVEYVljDDznQqc5XnQ/zQ7RHD7/M=; b=M8ktJiPMRHA4Cw54Y3C8naqrCBd+1qLnLWcHC06uP/Wl/UBgGvFlLFiLk4V/h1okJA F+FYK1zzh5ppqii2lpzobdbV5ynFQzBKw1YbUaI/6GkOH3B9ogwLrSA1HZk984Tb5KVB qCmaSuePP2h31PrTgTah6fX6f6+0X6BAhOryoetK3u+DOr6mKxCV1ja1KJzw1vFxwKzx /eKojjZ3Y82MYNTqgy3z7ss2NeL8+eNGDhSYOYBl9vyudiMFpfxr9/2SSSne7R2qXoNO NkKZXrfAdSMH/cN7lBc/5yfLf5DWOZF+AU+7YGZUtNs+obOPCW8wAd93yOjhXG3F3zyv KMCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rbf24eoC; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-133348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i12-20020a0561020a4c00b00479dbf1aeebsi353882vss.644.2024.04.05.09.37.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 09:37:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rbf24eoC; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-133348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3B4FA1C220E6 for ; Fri, 5 Apr 2024 16:37:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71C4B16F275; Fri, 5 Apr 2024 16:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Rbf24eoC" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3F951CFBC for ; Fri, 5 Apr 2024 16:37:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712335057; cv=none; b=lxc4Yp6jFR3TGdmeHVC0oGG6HMnion/Skr3t+mgzGDC2P8tKitW6jsQLrhiBy2U/bcCjAjOLkB5bdmvS0LaZMPlRghPy7wVmocwu8dmf3c8b0JPPvlkNZdD7BYkBiHbRUpWOnCkfk2652FEiZX2KxdWqEdXsSQFTFS5kmtrhSfY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712335057; c=relaxed/simple; bh=TwC7u7kRLVrvNcf6B/odAd8Zu0CBkmKdy6vVGMGRGnw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZeP5QUSO8x5CgsSDZVtKElqVm+I97mKQD/ODA5+0jzCGe0FhbMoUnX+9SE7BAHjNncq4i15JeHFRHGLpDJxoWDZulBSihK5VqMb8GeVPYKUuAUsgzxjnbNIyDL5f5+zzgEGIBklZeSXFzUtpDAUfRosfVtELPIEh2RJJvR4W4g0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Rbf24eoC; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712335054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HhqXEsjcQfRnbT+Watd5B6B0qa6OPofOH0VzzxL2RKw=; b=Rbf24eoCLCCZ6vI1g2jlsUNPJriVqLxF6KAAtu4aQEDpwnsW6jXo38qJ6u92J6P3RXrv0S 1lp4BIWfwEkMukyuQ5E2ZFzQkbd/qHydz4I0CLuWWrJ2tVpQaVPombg4TPlfKM4nKRFR6z W5Kt8nR0q3p5I7Y1O6SGQP8Gijl/k0E= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-D3NFh-wpNHmtY5uJXGlHcg-1; Fri, 05 Apr 2024 12:37:32 -0400 X-MC-Unique: D3NFh-wpNHmtY5uJXGlHcg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-41545bc8962so12115135e9.2 for ; Fri, 05 Apr 2024 09:37:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712335051; x=1712939851; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HhqXEsjcQfRnbT+Watd5B6B0qa6OPofOH0VzzxL2RKw=; b=vaho4rDnO/SKhQaXxwrW26dbq85tXxMrJthxgr4lHxKZoH50Mzb3zaKBCxuphvww3y RV2BL5BBrWVwS4RSkZrcUKVnnxbw4fye51XS8c6SRDjwkQcYqfmY8kQyPHLqV2RzJYiO C83TrR6S2MBO3i4DScrWFmJ7Jg8ut3jMuYCXn01KjukQFhXCmGt3RbGCk/I8A4u5WiIW dMTtg8YA23PC3orDhfE/nMuacLzKQzEF0Rz6j2dkTDAqu3NQaBGjQlgocRjl7j9ZulYS 7fZYZNfKkDn9Awnm1FpACLu5JXiI+NYr/Q53NtW9PmBqdmFUXHR9UuFBf6EuHj3Abz5u cYdA== X-Forwarded-Encrypted: i=1; AJvYcCWurTU87OIKP2YzLUV6azK+M6ciN0uZbgCoOxVa3kIrDGpwgLPfCL1ITgZwu7fZcklkxvbr1EMtITSvuiIkxnFUW5DHzjGoTvltDvgc X-Gm-Message-State: AOJu0YzUGeZjk45f8S500Y4Ur3IwJYjEKBkDuu7SFxofO5sbImXHHJzC GgBiXvvcX7wMkNCSMNUSsNYj7R2/IDM8E4G8ymxV5T1IjLQ+8ZkFJCjT7CFyThLnyPlJ+0JcxN0 DNwjic4mL0h4D8fWqgtD7IqK3YobqfG/9D52KFY4Ja/JzQX+F4+d3yCzIG2EMcg== X-Received: by 2002:a05:600c:4510:b0:414:767e:6e76 with SMTP id t16-20020a05600c451000b00414767e6e76mr1596283wmo.21.1712335051630; Fri, 05 Apr 2024 09:37:31 -0700 (PDT) X-Received: by 2002:a05:600c:4510:b0:414:767e:6e76 with SMTP id t16-20020a05600c451000b00414767e6e76mr1596272wmo.21.1712335051297; Fri, 05 Apr 2024 09:37:31 -0700 (PDT) Received: from ?IPV6:2a02:810d:4b3f:ee94:abf:b8ff:feee:998b? ([2a02:810d:4b3f:ee94:abf:b8ff:feee:998b]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b00416306c17basm2328956wmn.14.2024.04.05.09.37.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Apr 2024 09:37:29 -0700 (PDT) Message-ID: <593a8479-741a-44de-a52c-8d34810bfb3e@redhat.com> Date: Fri, 5 Apr 2024 18:37:26 +0200 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] nouveau/gsp: Avoid addressing beyond end of rpc->entries To: Kees Cook Cc: Lyude Paul , David Airlie , Daniel Vetter , Dave Airlie , Ben Skeggs , Timur Tabi , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, "Gustavo A. R. Silva" , Dan Carpenter , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Karol Herbst References: <20240330141159.work.063-kees@kernel.org> Content-Language: en-US From: Danilo Krummrich Organization: RedHat In-Reply-To: <20240330141159.work.063-kees@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/30/24 15:12, Kees Cook wrote: > Using the end of rpc->entries[] for addressing runs into both compile-time > and run-time detection of accessing beyond the end of the array. Use the > base pointer instead, since was allocated with the additional bytes for > storing the strings. Avoids the following warning in future GCC releases > with support for __counted_by: > > In function 'fortify_memcpy_chk', > inlined from 'r535_gsp_rpc_set_registry' at ../drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1123:3: > ../include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning] > 553 | __write_overflow_field(p_size_field, size); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > for this code: > > strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES]; > ... > memcpy(strings, r535_registry_entries[i].name, name_len); > > Signed-off-by: Kees Cook Applied to drm-misc-fixes, thanks! > --- > Cc: Karol Herbst > Cc: Lyude Paul > Cc: Danilo Krummrich > Cc: David Airlie > Cc: Daniel Vetter > Cc: Dave Airlie > Cc: Ben Skeggs > Cc: Timur Tabi > Cc: dri-devel@lists.freedesktop.org > Cc: nouveau@lists.freedesktop.org > --- > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > index 9994cbd6f1c4..9858c1438aa7 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > @@ -1112,7 +1112,7 @@ r535_gsp_rpc_set_registry(struct nvkm_gsp *gsp) > rpc->numEntries = NV_GSP_REG_NUM_ENTRIES; > > str_offset = offsetof(typeof(*rpc), entries[NV_GSP_REG_NUM_ENTRIES]); > - strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES]; > + strings = (char *)rpc + str_offset; > for (i = 0; i < NV_GSP_REG_NUM_ENTRIES; i++) { > int name_len = strlen(r535_registry_entries[i].name) + 1; >