Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp33255832rwd; Sat, 8 Jul 2023 08:04:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJX3pDrXRBHtXetI+8oCHj0f3MXutJiTHi7RS/QAole7D2VHnA7doA/ROcWeROGEEq7yL7 X-Received: by 2002:a05:6a00:84d:b0:682:54b9:1093 with SMTP id q13-20020a056a00084d00b0068254b91093mr10580702pfk.15.1688828661463; Sat, 08 Jul 2023 08:04:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688828661; cv=pass; d=google.com; s=arc-20160816; b=AdwFrfzRL8eaQZ4+cESGMEmR4EsAb4zJ1ViNs/o/6zJjOtvndXuoobk+bWvbTtgHSD SD0wqo9xJSpKWDdxhA88/OAFagt+Yvq58boWo6VvpXUZOsvRUQoaT92vAwwqZ9ZZROTx 2V30jBVk8BhVSIQjoi/1tdqIcuYMq/c2FQh9xc5hm6zlODq1hbu3P0v45Fgm7Nro9fuB jtvdfhbaqt0B9t/hpECwzKbbRE5WzKd+P36kWHgXj/gg9usglae1IA+XTM9dXVY5c/ke 3RY9qliZ5fMdWSNb43VCEQEwMDuh+X9Rkl1DLkDqxGPpaM7Q3aBMC1TgRzTNV51k/6vb E4ug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :msip_labels:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=nuBt5+wMhiCrphCcMIJiLv0EYchhCVRfBdVc0JpZMQQ=; fh=pDXjTUmnyCdKJum+dGl0CTFU9lCTQ+qVPx42cSlKs08=; b=nDV1G3JU2IsNjw4rSN0Mtnho0eD3BKB+hh/htK6nuWab3yFCy9F8DFAqee9zLReLe4 dId5N2uuHpmPDTCT0/UXOT+AxWOpfs1ldqp9TsBhVlGQ58fkI3gQhHBTOYmfXz+fXt69 gkOd8/WwmOVjK3vgyWBP0TrU1FY+mgh74hzE/j2Na3JuWd4t5dJaqCm6xofpeR0mDYIb Ge9vagMgslH7+pchpRk/uTe0nEcs8m8fNIeWqilemXQ/TuQtepsgyqwknbXDFytHvSZF Wh3AUfIv5vfWBbh7S1jmq1JxXNajdVtlOTgguXkZbHj2S88f0UXLeci46A985khDH/UR Bt7A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=eImevsG0; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020a056a00081400b0066882062113si6167391pfk.9.2023.07.08.08.04.09; Sat, 08 Jul 2023 08:04:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=eImevsG0; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbjGHOhh (ORCPT + 99 others); Sat, 8 Jul 2023 10:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjGHOhg (ORCPT ); Sat, 8 Jul 2023 10:37:36 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-centralusazon11020016.outbound.protection.outlook.com [52.101.61.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13137E56; Sat, 8 Jul 2023 07:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vm/KrSwHp7lHfzTwwxgvh7XboCE88ukhK/le1kpdlZi5L4322f1IEGa0J2sq+zQM8ywB+d4K6BY5yywfZcBc6PCUjM2rPOxYksE1pfUe5d5Sa6yps4igL58G3qBm6KKjDn+TIwUqHLs5AufxtOXDeWc4V1SGH03EpmzMZ+NjQTw9ZyGy0IcCYKqULczOVTAK9PL8p/hN3PySI9QET/oJbLqsDqm5p1Bh+oZ+5oBKleBz752564zznWbYsiQZwfC0v3NQxUxUqJLBmGR7jn//bUsWDfdcwE7RR2REIdkrVfqFh38HxdvvF2d9XJEnBA6xgjBpFDgKRgyp56OqxlKkfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nuBt5+wMhiCrphCcMIJiLv0EYchhCVRfBdVc0JpZMQQ=; b=czgLwwVtWKt6VVN27DOkxaVYTF4SKi4tR/uIalOaa1lH/I9SwqmADnO3xMC17GEBD433Deer2rbGpBu/Mue4H7qn5SWzr/a21NJTzOcFS/xhcYoF1eXrIzCt2UTSTdZhXcGPPR5TBU6FwQwhoidBN6sMxa2UwJxtWGs/v+EDrAMOOVUkqOvKEcKD/LMRRd6aPsPK5jbwSNKiONGwUh+O6Ov7d63FZTKnnawMposfnbo+AFlVYEhgSJ/Fcofir0Iw30WJf21iXqurLSNvy7EYVOxSUfXyc4AzibRU7sMVkNhNXtNg8r49zb2FSG5kSgyWHEJVrlHB9urpyMMEnFC+Iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nuBt5+wMhiCrphCcMIJiLv0EYchhCVRfBdVc0JpZMQQ=; b=eImevsG0z5nkBiykjDT3tD0JiC8TFnD0PlmUgwrTh6CQNAR4VQMiVbjISHJDuQXDQEyoQBQR/lBJI9SVJzesAmlHCeWWNuWZX6wqddqHn9bv3uX4/+3saWbAsOTWEsSeYn3RCWc96FkfpZg8meU0ZGlo/LDUC1Zt5jqVW4CW1X8= Received: from BYAPR21MB1688.namprd21.prod.outlook.com (2603:10b6:a02:bf::26) by MN0PR21MB3583.namprd21.prod.outlook.com (2603:10b6:208:3d0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.14; Sat, 8 Jul 2023 14:37:30 +0000 Received: from BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::733d:6263:4482:ba25]) by BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::733d:6263:4482:ba25%4]) with mapi id 15.20.6609.000; Sat, 8 Jul 2023 14:37:28 +0000 From: "Michael Kelley (LINUX)" To: Arnd Bergmann , Jiri Kosina , Benjamin Tissoires CC: Arnd Bergmann , KY Srinivasan , Haiyang Zhang , Wei Liu , Dexuan Cui , Paulo Miguel Almeida , Dawei Li , Yang Yingliang , =?iso-8859-1?Q?Thomas_Wei=DFschuh?= , "linux-hyperv@vger.kernel.org" , "linux-input@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] HID: hyperv: avoid struct memcpy overrun warning Thread-Topic: [PATCH] HID: hyperv: avoid struct memcpy overrun warning Thread-Index: AQHZr0llfkBz0jWXH027nvPaFIvXdK+v9I4w Date: Sat, 8 Jul 2023 14:37:28 +0000 Message-ID: References: <20230705140242.844167-1-arnd@kernel.org> In-Reply-To: <20230705140242.844167-1-arnd@kernel.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=e5f54eeb-8e83-42b1-9cc3-0abbdbcd03c0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2023-07-08T14:36:21Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BYAPR21MB1688:EE_|MN0PR21MB3583:EE_ x-ms-office365-filtering-correlation-id: 301e365f-2e21-4455-ebe9-08db7fc0da99 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Tg/EyQrGRK0jkZn9UBcAeXpKj+RRAUel6MHxNPjIVJsWZLEQLoEF2wEWZwRUDRdKS0/+qWFPjYEd3nj50o2jfWRIeYxgZ1SFFQ2YBQkjU9WWppAaLMgiZykvKFNclffcMb5q+gnLmYfnpstML5imQ/iin1wjq4w1aMjFB7pPhuUeqissFpiwzDUCv9xb/X+j/SKw1Zt3OaR/1JP2qIw9AOrnV7AeaWWhiE3nYgCj/GL8tqHN7xxYRZzYCt40S882Y1LKoDqFUNUEr1YCUPDw+GP9wLkuQB02kVmDlpZJmhnFuJDM2u+pQqeXYM95xwsHXKMsIOEGbmUHxGkrtF55zKlVejZJAg7GINojhlDm6eQsVPeAITGBFlVJvdeCGCWFRJIHFAyuo/2v3qzklcs3C6ZC1hCoMD/QI2EdUY+I32U6rq/Eoywqia1nNo15i3Rj4420v/DDXeyFxIZUh5iMaorAOoN+yjtbdNMtidG6qICVi9KIoJYR7QnSBWfHudAm7bHGRk3d2ow+DyVF4qXMvTHmQrEGaHIf++maVokWTezAZRpxkQKZM9Deoccd/nPKo1Oxm46gSK0HhC0ErgAJhukss/H/ZNzeCHwAhoVFlyPARJ8c5ZvjxFByQYnTE4njH0PC6Uf7Q0ngQP3dVNd8ki2Eqp9VBdRVsTHOJjBIrRo= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR21MB1688.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(39860400002)(396003)(136003)(451199021)(10290500003)(478600001)(7696005)(71200400001)(76116006)(110136005)(54906003)(6506007)(26005)(186003)(9686003)(8990500004)(2906002)(66946007)(41300700001)(316002)(66556008)(66476007)(66446008)(64756008)(4326008)(5660300002)(52536014)(7416002)(8936002)(8676002)(38100700002)(122000001)(82960400001)(82950400001)(86362001)(33656002)(38070700005)(83380400001)(55016003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?jDV/pkq6hyyKTwN/WlMndNnERKnZZsb3bLJ1rJnBX+YCSyqt6Al71YzmU9?= =?iso-8859-1?Q?wad1oQpktnabHi9GlLHaNtMTT2KODUTCHUpQFSonY26ZYh7Wnkt2d1KDjC?= =?iso-8859-1?Q?shHppTw14R14jatBKCJnht4zAkeY6KMOPCE44Tlw7c7Csxp1cobzqw68Sa?= =?iso-8859-1?Q?HEH1yiV1Ji6U5B3J9F7X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5k12BGYdPP?= =?iso-8859-1?Q?B7CLWnTVY7hnXNGPRZGNgvK7G1tzXRjXv5B9mLwl6oamMdWm7sR3gGwp5W?= =?iso-8859-1?Q?OtsMctTMWnFpcfr6EtNU7sf8kvzZ8D1SCaQwOkuhweIYAPbxxkGaV33IOI?= =?iso-8859-1?Q?7iS2S1dQd0hFujQ47CHkq8UcNk/OZLwpM4nWG0pHZoMVhEhbcSzeJuWl1H?= =?iso-8859-1?Q?OG0jv4FlcHIyQZb6Y+UGfCOEdZ3/0nzqK9xjvOfK73QOCo3yRRSy9irkOd?= =?iso-8859-1?Q?bphGSY1a+gY8IfG+qME4+qgpXia2migoMhCbgc1MOe1hQM9LYgL5emkPM3?= =?iso-8859-1?Q?uUEHJJVQmLnbFHUCBq1418HlW4wcgmI8NOvunCeBvKvaOn478qJQNL5t4E?= =?iso-8859-1?Q?IDbuSyZhcUR/VCOqB7PWFo5gr15FeIl9MWSa61MDnCByT5+5qG+sllOTwz?= =?iso-8859-1?Q?vktJieGf8WwWCjCWtTIjNkmpNMstN8bL4FqI1H3dXylP5Qq0sqCQDNDleu?= =?iso-8859-1?Q?qZh7afILC6OCq7Nq/SBfNqK3h6jCMqrwEIbWJ62CzTjgqi3ThJ5Cpitxg7?= =?iso-8859-1?Q?ynNGtc8gBNwupCJohcc3KDsmIhDIz5yVEGSrQjqN/sByaY11veuua06Q?= =?iso-8859-1?Q?=3D=3D?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR21MB1688.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 301e365f-2e21-4455-ebe9-08db7fc0da99 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jul 2023 14:37:28.0691 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: KTyxm1XrYK67EFK0xScq0miR8GH+KR45z2yeHU1n9n3wx7omPVSXjYCab3Olbm22GV6lN/5RFrVLeJ2ZBhixRDJtwc71ujVErbthVjmnwy4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR21MB3583 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann Sent: Wednesday, July 5, 2023 7:02 AM >=20 > A previous patch addressed the fortified memcpy warning for most > builds, but I still see this one with gcc-9: >=20 > In file included from include/linux/string.h:254, > from drivers/hid/hid-hyperv.c:8: > In function 'fortify_memcpy_chk', > inlined from 'mousevsc_on_receive' at drivers/hid/hid-hyperv.c:272:3: > include/linux/fortify-string.h:583:4: error: call to '__write_overflow_fi= eld' declared with > attribute warning: detected write beyond size of field (1st parameter); m= aybe use > struct_group()? [-Werror=3Dattribute-warning] > 583 | __write_overflow_field(p_size_field, size); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >=20 > My guess is that the WARN_ON() itself is what confuses gcc, so it no > longer sees that there is a correct range check. Rework the code in a > way that helps readability and avoids the warning. >=20 > Fixes: 542f25a944715 ("HID: hyperv: Replace one-element array with flexib= le-array member") > Signed-off-by: Arnd Bergmann > --- > drivers/hid/hid-hyperv.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c > index 49d4a26895e76..f33485d83d24f 100644 > --- a/drivers/hid/hid-hyperv.c > +++ b/drivers/hid/hid-hyperv.c > @@ -258,19 +258,17 @@ static void mousevsc_on_receive(struct hv_device *d= evice, >=20 > switch (hid_msg_hdr->type) { > case SYNTH_HID_PROTOCOL_RESPONSE: > + len =3D struct_size(pipe_msg, data, pipe_msg->size); > + > /* > * While it will be impossible for us to protect against > * malicious/buggy hypervisor/host, add a check here to > * ensure we don't corrupt memory. > */ > - if (struct_size(pipe_msg, data, pipe_msg->size) > - > sizeof(struct mousevsc_prt_msg)) { > - WARN_ON(1); > + if (WARN_ON(len > sizeof(struct mousevsc_prt_msg))) > break; > - } >=20 > - memcpy(&input_dev->protocol_resp, pipe_msg, > - struct_size(pipe_msg, data, pipe_msg->size)); > + memcpy(&input_dev->protocol_resp, pipe_msg, len); > complete(&input_dev->wait_event); > break; >=20 > -- > 2.39.2 Reviewed-by: Michael Kelley