Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6043911pxv; Thu, 29 Jul 2021 05:12:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyp+eFmL+theI+MLi43khgF/EnzyvbA/y8Lkhye+arjdQLJA9jL05kK1ilB1OnMNnCffPd X-Received: by 2002:a17:906:c251:: with SMTP id bl17mr4338539ejb.219.1627560726171; Thu, 29 Jul 2021 05:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627560726; cv=none; d=google.com; s=arc-20160816; b=ulMUXMkf9UCTfm4m0W8V0UbUhPNCtH/W1tRAopjLIp15F/GRKFsYCRv8zjVkq87nem 7Silk/NuXH4H17YpLcjV2356VgfM7p4epLghWuljdqMlkD5y0631vrwjQ95JWKF4ui96 mhZv7XRs0w9J0tceM9fV62lAteo/uoFSuItRkiLpJRzj4hQf9c5jp25dW5GaDbf/fon9 e03ClKO57avmMag0yM2WBZqG7wfse8g80hpczqnZqqr8bNs4qPmzqoPEE74VVWC/rBlW Nyh3ZnIsIg4yJZcwfqhyHeM4ok457svaUDQf22PHwhgDEcnmhxz6p0dr91o2vO7KMNz/ wjMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=8Nz6vB9p8A0wBJs6kkDYFIrrTzDZDT+uS9XB0IAUyko=; b=I1Ah6fLr019j8DxTZX/vhTaen5lCXlMGO14q24vG/fvGt46N3cw/tD+JvwrKNZYx80 JQZWPr/DRYvR9FTtMH2DGOM7UIWVCXhQRyyi22G1FHYURHYUgfGmAzWxGshVCglqKRFh AU3e+oD3gX9kZMyvdwEVsSa6icGvjCtS7NDJ4TjHwARghsQkgvqEWm6p4vliSElC7NWR QVD9+WlEtsaa/shreWH4AERGQ/6aAC+aYUEuV/yUS9jqb81rfbHhhqMnD0QM6iQvmw8D m0cL5n+ODthE9/dI23DhUT2fav4xOKba6+jm+xbuLT78tEbJMp5UDEBpr9NABWGXDCOA RK4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=IX9QYptY; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si3015103ejd.203.2021.07.29.05.11.38; Thu, 29 Jul 2021 05:12:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=IX9QYptY; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236745AbhG2MLg (ORCPT + 99 others); Thu, 29 Jul 2021 08:11:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235169AbhG2MLf (ORCPT ); Thu, 29 Jul 2021 08:11:35 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E76BC0613C1 for ; Thu, 29 Jul 2021 05:11:31 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id r2so6689931wrl.1 for ; Thu, 29 Jul 2021 05:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=8Nz6vB9p8A0wBJs6kkDYFIrrTzDZDT+uS9XB0IAUyko=; b=IX9QYptYV6st0L1XmOo2+ZVTD1czWMC0yv2A0wEKs5uhoKxyG1M8hYGFid/Rc9caoJ g3s8uihSolFDNGNVDmh/KcSkUnjuvxHUSlZem764aZk2d9p45qyVKzkwnR65zmpbIjwe oixk5YiEQMSk6egRcnGh8U5DvdkvMLdRPa8MA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=8Nz6vB9p8A0wBJs6kkDYFIrrTzDZDT+uS9XB0IAUyko=; b=ZHNUc5O5TBWhMalgqjPXIkPSWPgOFky6IWcK2BJvWrtgzHBz8xxutxo6QC9srqNwgy EjF6fZzPJ2y50JqMG6V9DQK6kWGHB68BQDcuDz/bml1bycgagPXLKLsFtjy4pv8Ztvpj hB8y0p0bNpIfJiNDsCeDdziZnV0yBzpURwiwoOo3r1la0VDhywI21oE6/GhfmH5h4kuK MXzIhjBpDuHGaISchGHBgktRJfgAaKluzDQ+afbpml3hRwB54qAcFmmY1oTQhQIudhfd iyGbT3wBXa3BOWyK390CwVYJTrttU+uwxapDUsHxZcwUFeK9lgUyJAHh4S8t73ekHB6k Sk/Q== X-Gm-Message-State: AOAM530yeOOgcbETv/QgeC3slViaSm5M8/xWNm9mOJ1i6QEY+mmXiacC VGyRxSXjJY/pHTsQZvU2y967fA== X-Received: by 2002:a5d:4e91:: with SMTP id e17mr4462754wru.7.1627560689971; Thu, 29 Jul 2021 05:11:29 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id a14sm3323850wrf.97.2021.07.29.05.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 05:11:29 -0700 (PDT) Date: Thu, 29 Jul 2021 14:11:27 +0200 From: Daniel Vetter To: Greg Kroah-Hartman Cc: Kees Cook , linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-staging@lists.linux.dev, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" , linux-block@vger.kernel.org, clang-built-linux@googlegroups.com, Keith Packard , linux-hardening@vger.kernel.org, Andrew Morton Subject: Re: [PATCH 25/64] drm/mga/mga_ioc32: Use struct_group() for memcpy() region Message-ID: Mail-Followup-To: Greg Kroah-Hartman , Kees Cook , linux-kbuild@vger.kernel.org, netdev@vger.kernel.org, linux-staging@lists.linux.dev, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" , linux-block@vger.kernel.org, clang-built-linux@googlegroups.com, Keith Packard , linux-hardening@vger.kernel.org, Andrew Morton References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-26-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 5.10.0-7-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, Jul 28, 2021 at 07:56:40AM +0200, Greg Kroah-Hartman wrote: > On Tue, Jul 27, 2021 at 01:58:16PM -0700, Kees Cook wrote: > > In preparation for FORTIFY_SOURCE performing compile-time and run-time > > field bounds checking for memcpy(), memmove(), and memset(), avoid > > intentionally writing across neighboring fields. > > > > Use struct_group() in struct drm32_mga_init around members chipset, sgram, > > maccess, fb_cpp, front_offset, front_pitch, back_offset, back_pitch, > > depth_cpp, depth_offset, depth_pitch, texture_offset, and texture_size, > > so they can be referenced together. This will allow memcpy() and sizeof() > > to more easily reason about sizes, improve readability, and avoid future > > warnings about writing beyond the end of chipset. > > > > "pahole" shows no size nor member offset changes to struct drm32_mga_init. > > "objdump -d" shows no meaningful object code changes (i.e. only source > > line number induced differences and optimizations). > > > > Note that since this includes a UAPI header, struct_group() has been > > explicitly redefined local to the header. > > > > Signed-off-by: Kees Cook > > --- > > drivers/gpu/drm/mga/mga_ioc32.c | 30 ++++++++++++++------------ > > include/uapi/drm/mga_drm.h | 37 ++++++++++++++++++++++++--------- > > 2 files changed, 44 insertions(+), 23 deletions(-) > > > > diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c > > index 4fd4de16cd32..fbd0329dbd4f 100644 > > --- a/drivers/gpu/drm/mga/mga_ioc32.c > > +++ b/drivers/gpu/drm/mga/mga_ioc32.c > > @@ -38,16 +38,21 @@ > > typedef struct drm32_mga_init { > > int func; > > u32 sarea_priv_offset; > > - int chipset; > > - int sgram; > > - unsigned int maccess; > > - unsigned int fb_cpp; > > - unsigned int front_offset, front_pitch; > > - unsigned int back_offset, back_pitch; > > - unsigned int depth_cpp; > > - unsigned int depth_offset, depth_pitch; > > - unsigned int texture_offset[MGA_NR_TEX_HEAPS]; > > - unsigned int texture_size[MGA_NR_TEX_HEAPS]; > > + struct_group(always32bit, > > + int chipset; > > + int sgram; > > + unsigned int maccess; > > + unsigned int fb_cpp; > > + unsigned int front_offset; > > + unsigned int front_pitch; > > + unsigned int back_offset; > > + unsigned int back_pitch; > > + unsigned int depth_cpp; > > + unsigned int depth_offset; > > + unsigned int depth_pitch; > > + unsigned int texture_offset[MGA_NR_TEX_HEAPS]; > > + unsigned int texture_size[MGA_NR_TEX_HEAPS]; > > + ); > > u32 fb_offset; > > u32 mmio_offset; > > u32 status_offset; > > @@ -67,9 +72,8 @@ static int compat_mga_init(struct file *file, unsigned int cmd, > > > > init.func = init32.func; > > init.sarea_priv_offset = init32.sarea_priv_offset; > > - memcpy(&init.chipset, &init32.chipset, > > - offsetof(drm_mga_init_t, fb_offset) - > > - offsetof(drm_mga_init_t, chipset)); > > + memcpy(&init.always32bit, &init32.always32bit, > > + sizeof(init32.always32bit)); > > init.fb_offset = init32.fb_offset; > > init.mmio_offset = init32.mmio_offset; > > init.status_offset = init32.status_offset; > > diff --git a/include/uapi/drm/mga_drm.h b/include/uapi/drm/mga_drm.h > > index 8c4337548ab5..61612e5ecab2 100644 > > --- a/include/uapi/drm/mga_drm.h > > +++ b/include/uapi/drm/mga_drm.h > > @@ -265,6 +265,16 @@ typedef struct _drm_mga_sarea { > > #define DRM_IOCTL_MGA_WAIT_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_WAIT_FENCE, __u32) > > #define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t) > > > > +#define __struct_group(name, fields) \ > > + union { \ > > + struct { \ > > + fields \ > > + }; \ > > + struct { \ > > + fields \ > > + } name; \ > > + } > > + > > typedef struct _drm_mga_warp_index { > > int installed; > > unsigned long phys_addr; > > @@ -279,20 +289,25 @@ typedef struct drm_mga_init { > > > > unsigned long sarea_priv_offset; > > > > - int chipset; > > - int sgram; > > + __struct_group(always32bit, > > + int chipset; > > + int sgram; > > > > - unsigned int maccess; > > + unsigned int maccess; > > > > - unsigned int fb_cpp; > > - unsigned int front_offset, front_pitch; > > - unsigned int back_offset, back_pitch; > > + unsigned int fb_cpp; > > + unsigned int front_offset; > > + unsigned int front_pitch; > > + unsigned int back_offset; > > + unsigned int back_pitch; > > > > - unsigned int depth_cpp; > > - unsigned int depth_offset, depth_pitch; > > + unsigned int depth_cpp; > > + unsigned int depth_offset; > > + unsigned int depth_pitch; > > > > - unsigned int texture_offset[MGA_NR_TEX_HEAPS]; > > - unsigned int texture_size[MGA_NR_TEX_HEAPS]; > > + unsigned int texture_offset[MGA_NR_TEX_HEAPS]; > > + unsigned int texture_size[MGA_NR_TEX_HEAPS]; > > + ); > > > > unsigned long fb_offset; > > unsigned long mmio_offset; > > @@ -302,6 +317,8 @@ typedef struct drm_mga_init { > > unsigned long buffers_offset; > > } drm_mga_init_t; > > > > +#undef __struct_group > > + > > Why can you use __struct_group in this uapi header, but not the > networking one? If there's others, maybe we can stuff the uapi __struct_group into linux/types.h where all the other __ uapi types hang out? Anyway mga is very dead, I don't anyone cares. Acked-by: Daniel Vetter I'm assuming this goes in through a topic pull from you? I'll leave the drm/amd one to figure out between you and Alex. -Daniel > > thanks, > > greg k-h -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch