Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4122377rwi; Mon, 17 Oct 2022 01:36:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Z3rxulLtcnXTWf28ZmJKdx3fp3yZ4psP6XDilojyUl+p5Kuy3O8h6Ws/8WdatLO2Yse0d X-Received: by 2002:a63:91c2:0:b0:460:609c:e60f with SMTP id l185-20020a6391c2000000b00460609ce60fmr9777523pge.447.1665995764954; Mon, 17 Oct 2022 01:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665995764; cv=none; d=google.com; s=arc-20160816; b=puhZF5FEQc5nQWW/eIdwtsGREXkKMzz8axe+gTyahtoP/uBMkYeaRHp5w9DoMm/8Z4 NrwZRpDc1ZqTsUl4ZhXrEl8lwjOhyryV/1OTtHVXVU60x5OuykLfD3Tz5jBenyIlTnHU Pjw6HdVd9j8KQcEKwVwCgrbRRxfKlg5YBA7bEXiPIEQOvsjfd1gY2gK1Z+jADJaX9o9C jmJjbkLbVsbEGuniaJbeE1Gd/cJYLa7UyAl9R/fSefkc0SjFTwVcmoA/ZX+YlFO5nniJ G5OzFJtZdz5dsuepQJvH5paWAVUc1evS+woA/2hoUSYAjqswMczfQS05JzKVbsqFwfTo rVMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ICZj4OzZtpWjbJoXyPcZEJISbo2i7c++c+5S4uuj5bw=; b=AkTmdgl5jwgvUQW34gY+ArQh83tlDtKUi2rpNKA2rjo0FObP24b8IITyM/rEZ4UNo3 yi0qu9+9Ta/CiJDIiaCQ8MzVp3CXu9C/SMefS5cOiWgenZbsJB+/1UXj2fF+oUYbercB 8PsdUQN1Vxy4owXWsmrmPeSiRFOvs/vy8smnpuqZaFh5CtGH4lU1d3QKYw/6ddIgqqqw 3Y4AuMtfvhtPD1HjyqnpxDiCGyZaU4iSc1GCtpj80Ul4dzKlQYeqFNUgR5s58PvV1Gpf Gwo2NScSkXAOy0yFPXZyt0EuePjsS5TNXPfXFUvdxhSoUEJ4qFn/ripP6uhF6NYe85J+ ZaAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=inQfYZtA; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s64-20020a632c43000000b00455074c7901si10704453pgs.36.2022.10.17.01.35.51; Mon, 17 Oct 2022 01:36:04 -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=@redhat.com header.s=mimecast20190719 header.b=inQfYZtA; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbiJQIbL (ORCPT + 99 others); Mon, 17 Oct 2022 04:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbiJQIbJ (ORCPT ); Mon, 17 Oct 2022 04:31:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E1BCE1B for ; Mon, 17 Oct 2022 01:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665995467; 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: in-reply-to:in-reply-to:references:references; bh=ICZj4OzZtpWjbJoXyPcZEJISbo2i7c++c+5S4uuj5bw=; b=inQfYZtAzlTFbPoLrp6ri60FCi9BLGB4W7Se7O9Y7GPsMc8NtnDEBe0jTPPaHZpuEq/zWL GdNEv/78wBMN0jkPikjA475AxdMJhRReEZIKpiahEu7ii9m9aZozcjOH3aXpPdvqDwZwR/ mZBzDV35kneATgazI0UKZxNKOCsTNSM= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-122-88dzus-sOMitcKXznQynPg-1; Mon, 17 Oct 2022 04:31:06 -0400 X-MC-Unique: 88dzus-sOMitcKXznQynPg-1 Received: by mail-io1-f71.google.com with SMTP id 5-20020a5d9c05000000b006a44709a638so6595452ioe.11 for ; Mon, 17 Oct 2022 01:31:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ICZj4OzZtpWjbJoXyPcZEJISbo2i7c++c+5S4uuj5bw=; b=D0DlH0GjKEKPOPwghuQtyoJsWGLykICqslqDkgrPuzH9EuRBBTya0sXlbgKW3NjusG rEsWwYmPsdhbxpR8Uo1tjS8FGm1UTED+Sno5KgzP0p5ux1Pl5YvzskvvUkY0nRkKvhrB 8tDDr90Vjo6aNmmL5UNQ9jSildblTFYrPDTWWbOMHDhT9W/HpQiZAkLnwD8XZsUJlsZC X03bhhY5TibBL/0Q3E/O6E0P1DSnGfGlFWiRpwhJfayW1lyT6l1kAn6UAJRv1zY6VB1s NL2ktvlGkCwXQyCuxOUq/8QQK3MLqZJTnqUoe1d40SYIXBztQaHFW9SOdx+eL1bHnf41 j/sA== X-Gm-Message-State: ACrzQf2TZxIyjbaZGThpA03dQsewN6TI6wDlp1lI9K2/PT7XLi+HvB9v 1PwKbFJ3chdjLlKqWCn494OO5uGm/6bZY0q1DxBy4m0mQQVU86/d6YZABy/k+xyWm2F1MhKpMYM 0HxJe3NC4+7HRewogpkQikGKo4MtalDRcosJm5DLP X-Received: by 2002:a05:6e02:194e:b0:2f8:fa94:9da1 with SMTP id x14-20020a056e02194e00b002f8fa949da1mr4232886ilu.102.1665995465542; Mon, 17 Oct 2022 01:31:05 -0700 (PDT) X-Received: by 2002:a05:6e02:194e:b0:2f8:fa94:9da1 with SMTP id x14-20020a056e02194e00b002f8fa949da1mr4232872ilu.102.1665995465281; Mon, 17 Oct 2022 01:31:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Benjamin Tissoires Date: Mon, 17 Oct 2022 10:30:54 +0200 Message-ID: Subject: Re: [PATCH] [next] HID: hyperv: Replace one-element array with flexible-array member To: Paulo Miguel Almeida Cc: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Jiri Kosina , linux-hyperv@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 On Mon, Oct 17, 2022 at 9:51 AM Paulo Miguel Almeida wrote: > > One-element arrays are deprecated, and we are replacing them with > flexible array members instead. So, replace one-element array with > flexible-array member in structs synthhid_msg, synthhid_input_report, > pipe_prt_msg and refactor the rest of the code accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/210 > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] > > Signed-off-by: Paulo Miguel Almeida > --- FWIW, this is Reviewed-by: Benjamin Tissoires Couple of questions though: - do the hyperv want to take this patch through their tree or should I (I plan on sending some fixes for 6.1-rc2 this week, so I can piggy back this one) - on the driver itself, please see inline: > drivers/hid/hid-hyperv.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c > index e0bc73124196..208cf8d981a5 100644 > --- a/drivers/hid/hid-hyperv.c > +++ b/drivers/hid/hid-hyperv.c > @@ -61,7 +61,7 @@ struct synthhid_msg_hdr { > > struct synthhid_msg { > struct synthhid_msg_hdr header; > - char data[1]; /* Enclosed message */ > + char data[]; /* Enclosed message */ > }; IMO that struct has no real use. We just use it in mousevsc_on_receive() to dereference the first field only, the header. So how about we have a followup cleanup patch that just removes it and in mousevsc_on_receive() we convert those usages directly to struct synthhid_msg_hdr? Cheers, Benjamin > > union synthhid_version { > @@ -99,7 +99,7 @@ struct synthhid_device_info_ack { > > struct synthhid_input_report { > struct synthhid_msg_hdr header; > - char buffer[1]; > + char buffer[]; > }; > > #pragma pack(pop) > @@ -118,7 +118,7 @@ enum pipe_prot_msg_type { > struct pipe_prt_msg { > enum pipe_prot_msg_type type; > u32 size; > - char data[1]; > + char data[]; > }; > > struct mousevsc_prt_msg { > @@ -232,7 +232,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, > > ret = vmbus_sendpacket(input_device->device->channel, > &ack, > - sizeof(struct pipe_prt_msg) - sizeof(unsigned char) + > + sizeof(struct pipe_prt_msg) + > sizeof(struct synthhid_device_info_ack), > (unsigned long)&ack, > VM_PKT_DATA_INBAND, > @@ -271,16 +271,14 @@ static void mousevsc_on_receive(struct hv_device *device, > * malicious/buggy hypervisor/host, add a check here to > * ensure we don't corrupt memory. > */ > - if ((pipe_msg->size + sizeof(struct pipe_prt_msg) > - - sizeof(unsigned char)) > + if (struct_size(pipe_msg, data, pipe_msg->size) > > sizeof(struct mousevsc_prt_msg)) { > WARN_ON(1); > break; > } > > memcpy(&input_dev->protocol_resp, pipe_msg, > - pipe_msg->size + sizeof(struct pipe_prt_msg) - > - sizeof(unsigned char)); > + struct_size(pipe_msg, data, pipe_msg->size)); > complete(&input_dev->wait_event); > break; > > @@ -359,8 +357,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device) > request->request.version_requested.version = SYNTHHID_INPUT_VERSION; > > ret = vmbus_sendpacket(device->channel, request, > - sizeof(struct pipe_prt_msg) - > - sizeof(unsigned char) + > + sizeof(struct pipe_prt_msg) + > sizeof(struct synthhid_protocol_request), > (unsigned long)request, > VM_PKT_DATA_INBAND, > -- > 2.37.3 >