Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29109290rwd; Wed, 5 Jul 2023 07:19:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEVkXvLBZVv0wGfPBUtKdxwbBy1rxMF+PNQqJjzO+JWsVrXooMSAyaU1lfZcztj0PfnWoJ9 X-Received: by 2002:a17:903:2351:b0:1b8:7616:82d4 with SMTP id c17-20020a170903235100b001b8761682d4mr19578670plh.19.1688566782138; Wed, 05 Jul 2023 07:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688566782; cv=none; d=google.com; s=arc-20160816; b=PdmjuyOliDQl+w8vw0n487oHR8cIrrQ5dLMFNezTqhOCkD8D4Sb1qK57ocPElcuh9K 4I7FrN3gis3yP/00tVpyx3WRtvDH9kwX88MiMvlzg+7KzY6KjBl4M0MstlskMi+tr290 WkPjXwOgV/9reCzLUptwhN+99vPbprPon+JAtDS830DItb8QXjKZfStZbcviS6i5nym6 k8/qGgWuDgoTZm0LD4uO2BrSlK97CiHETioRIW8pZhr7s6C6nYcJNZLec0RdQ9hlb16T zomuQZcMv0Ahv6hQ7hrYIQkUnd9+h5i5BkTu2X7qADOSrToDs01N0Fr70GOIsYbAqHv9 DwPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ir3/x461lH1DvkNO2K8DshBkSin2qWHJmZoyv/+E4J0=; fh=jQx/OM00VL0I/YT8WM9trZ7LiBSkv/6pomkSQjpF13s=; b=UhczC06iXfTgoMWE6sgXzgv8C9Oug4YqkOdrMfP0OcTe6soCDtVt/MscgwtPGZCvme olq9IBJKAKZJcuI32Wo2GoRRkyLrY0iXPYoOKH3gSIahyt3x8zS4TfgQl+ji1O3G3CnV uSvfjiiCSIAO+hve/NSh4/RsywE3mlFrOFPh6rG3vKm/CNx0Qgcoulnh7K8g5ySGh5Hp xIrBq8EYj/AN1PC+1zB5mwI2lBQjZj1U5bBQWEx7PvhDVbkah4XGzzeCQFVRpH3mTCSP i+oZGo6rr6tEWWistNJzBie3wydjn+CqQKC92dtqDyscRjI4sIPBke/szME2FsswsM2W fdGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bTRx9QYe; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a170902ead100b001b04741042csi17999762pld.93.2023.07.05.07.19.28; Wed, 05 Jul 2023 07:19:42 -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=@kernel.org header.s=k20201202 header.b=bTRx9QYe; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232441AbjGEOCx (ORCPT + 99 others); Wed, 5 Jul 2023 10:02:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231865AbjGEOCv (ORCPT ); Wed, 5 Jul 2023 10:02:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB6211B; Wed, 5 Jul 2023 07:02:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AC71A61568; Wed, 5 Jul 2023 14:02:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE4E5C433C7; Wed, 5 Jul 2023 14:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688565769; bh=8Pv519rVX2nyzfcP+WWJAfxHrjLTPQrVejjsds7b0e8=; h=From:To:Cc:Subject:Date:From; b=bTRx9QYeOOUu652xyFmZdnhpFBlT1LXlf0Ecjj9AqPmaZ+k4P5cbVpk6enhALEj+4 a++Be9rRcL1yiFdllRaQpJkGq+/dACPEV0zCo8uGcqIMkwlkcT4Ast+4B3zEqtA1my 1yBNwB/rHhuV7+nPSGNDHyjhl1Y31bpbXvZr1mlYn5elxSVYB5RM2nn4wn9qN5bmxL FhXk8K0TM+LeSS3LrDieZiEoszeAJyznP28Jfz7n7JlnTk3REgjOePQES9Lrc3TQHq SlhmZXawVNCyXfrzkOfyjPxviE83s/157jrxJcl8wZPOP79iNgmJs7hVoxKps5UvLW XTlf78IsOIZ2w== From: Arnd Bergmann To: Jiri Kosina , Benjamin Tissoires Cc: Arnd Bergmann , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Paulo Miguel Almeida , Michael Kelley , Dawei Li , Yang Yingliang , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-hyperv@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: hyperv: avoid struct memcpy overrun warning Date: Wed, 5 Jul 2023 16:02:24 +0200 Message-Id: <20230705140242.844167-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Arnd Bergmann A previous patch addressed the fortified memcpy warning for most builds, but I still see this one with gcc-9: 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_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning] 583 | __write_overflow_field(p_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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. Fixes: 542f25a944715 ("HID: hyperv: Replace one-element array with flexible-array member") Signed-off-by: Arnd Bergmann --- drivers/hid/hid-hyperv.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 *device, switch (hid_msg_hdr->type) { case SYNTH_HID_PROTOCOL_RESPONSE: + len = 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; - } - 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; -- 2.39.2