From patchwork Mon Oct 17 07:51:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Miguel Almeida X-Patchwork-Id: 3260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1323968wrs; Mon, 17 Oct 2022 01:02:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6A/hmwJn/JjFfP9M/ssXtICEhhx/wivoU2/wY26OKB0/zdxxlWHz39UA5lEv4Uf1xkUxFM X-Received: by 2002:a17:906:8a51:b0:78d:acdc:b7d3 with SMTP id gx17-20020a1709068a5100b0078dacdcb7d3mr7528045ejc.214.1665993745825; Mon, 17 Oct 2022 01:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665993745; cv=none; d=google.com; s=arc-20160816; b=xBWmPkt2x6bX1d/oBe4XSQgbvkZwb648WviZYBvjquPdYFx/Ar88v//Xm7LxIfNSAA p45qDG6SrBcYYc8tC7D6Wjxybxh7X/w4exRhpmDM3BkM+JcPeTgXPOs6qKFN88uC0LJd JrAg6kBkGJ0mOJ3qI4RVkF0SZu3iynzW6IyJK5PZSp+JhyHhSVMmmm0PY+PyMHcNCGAX oZnGe7ac82vQ7qPwXzCSTDJh5amzV+A+4MgBjtUM6C/KSORwz/ZvoZvfkszp4qEEQzSv DI67Ks0/GUXp2JMze8v7Bk9u5jK+9rn18oxkugGXvMVd+TbcSaDHYGgKRBAgPuL/bWne UCPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=fSRrdzVHidQmdaT3eWjePmJqgOjvcCUYpgRIpnaOzjk=; b=0syzt6YI8Tz1qdJp2VPlpoupgslbaVkXTY4y0VgAMyX6QuouU2kHtryVcAWVdpeZ+q zqJoVxXptb2ufYvWWI048i95toFG8RUlWUjV1xNmAZsJ78Q5wOFjy6Sd7yOv/wGggD8r OWZY9lba20g4rrjA8t5pncdST42Mj7o7GklimsotQoENobF6m+ZrzCnRRPivf6PGFSrh YWkpU9gqkNAolY3tJFxKbPzLrcrCjTYC/RyduuYYb/2gjOIGSmXh+2bACm0GxBV65L8D lKGkW7FT8QGQ0sq7yPNtTqN7G32o0McaSFxBfvpkn4j3Efv2hh0by0jUQK6/T05BtngE 6hMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eBHLP+PH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he6-20020a1709073d8600b0078d9c781853si8660294ejc.607.2022.10.17.01.01.57; Mon, 17 Oct 2022 01:02:25 -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=@gmail.com header.s=20210112 header.b=eBHLP+PH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbiJQHvg (ORCPT + 99 others); Mon, 17 Oct 2022 03:51:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbiJQHve (ORCPT ); Mon, 17 Oct 2022 03:51:34 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7C6CAE43; Mon, 17 Oct 2022 00:51:31 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id q9so9749636pgq.8; Mon, 17 Oct 2022 00:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=fSRrdzVHidQmdaT3eWjePmJqgOjvcCUYpgRIpnaOzjk=; b=eBHLP+PHw8gAJVBUUXK+CVjZYlQQRyFkUO+0b5pdPcT57o4NFWkDAqgKyM8eBreZeF dlwz60eL+1cmFVCeae7RQgPbhKMNA7UqWWd0JnfKp3kr2cFg5xsYyu3CwIRFkQjcPscV yhv9cG57GYZP4OJHVQ8YAzWmssGkq6HscDYXvuzd9l8/NfMbBpnRzyh0WWnG9WshyFWH t5wT4eAXIKGXNC7lM/l9V4AT/bQTVobyBJxd7gSijqoFBo75d/ylLtuQmyyRPfSIryoN +SuU7iQfA6p8aCEXiaC4uyGS2VCyDtyVNC6AbYPbhwl/rIAJ6lwchZfFHOWVwnp6qr4Q 5gvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fSRrdzVHidQmdaT3eWjePmJqgOjvcCUYpgRIpnaOzjk=; b=UOAE3lWAePD7DyfK8+AyX4+6+G0TGlvBM9oPuhVSddYfMI9vwf69O5JlX+RLVAxuEV fwrAPOPdlmQ6u4FbSlI/ANB58JHg2DI/lGJ+1EGgWR2xil0iO1hj41Uyk46qAD3FlDjV pw6TYqqD2zwSqMe+l594ChF/GdAGmRZyZEBM1y3dHKA6CQqCACrC7RCBFDEoVU/RzUwM HEWqU4whCFea0o/LT1LLIumscny8FYqnZ0KJeQIrLlzZrSHlB8sYHNqZJG+i+kPWEpIv +ZOqdSYeB04sNMRNQYyIwmEpKK/4EGuhOe36vo0AKp6CnfRco5oOjvyVOYn5Mmp2OP4v GAyQ== X-Gm-Message-State: ACrzQf266LlQasMxZOAIXTe3Bg8crWV2pN6VenLSRAqKRCtJUmihHVUy XuqDfKKmoBK3SDI+pxTkVihcQdqusorKTA== X-Received: by 2002:a05:6a00:134f:b0:563:7aa8:5cea with SMTP id k15-20020a056a00134f00b005637aa85ceamr11107925pfu.69.1665993091229; Mon, 17 Oct 2022 00:51:31 -0700 (PDT) Received: from mail.google.com (122-58-209-93-fibre.sparkbb.co.nz. [122.58.209.93]) by smtp.gmail.com with ESMTPSA id x89-20020a17090a6c6200b0020d43c5c9a0sm5576400pjj.18.2022.10.17.00.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 00:51:30 -0700 (PDT) Date: Mon, 17 Oct 2022 20:51:22 +1300 From: Paulo Miguel Almeida To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Jiri Kosina , Benjamin Tissoires , linux-hyperv@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, paulo.miguel.almeida.rodenas@gmail.com Subject: [PATCH] [next] HID: hyperv: Replace one-element array with flexible-array member Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746921057821372017?= X-GMAIL-MSGID: =?utf-8?q?1746921057821372017?= 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 Reviewed-by: Benjamin Tissoires Reviewed-by: Michael Kelley --- 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 */ }; 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,