Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp369921pxb; Wed, 18 Nov 2020 06:41:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTHSz8BUZ6sXpT1AOSJemepLdewIaRCjLSSCCkNvRqRKoqRi96Ai7HMRlwkAoE4fXEm2Eh X-Received: by 2002:aa7:da81:: with SMTP id q1mr26003861eds.14.1605710517652; Wed, 18 Nov 2020 06:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605710517; cv=none; d=google.com; s=arc-20160816; b=zhwteoV4kNzL2MWH5+XotH5+COX429UpH4XrNRa/yGwcz52MNz5qUq42c8UgFbL92j +B9cse5ZitpdOLjbdJlJnxIiqO9k8xWI7mS/knTkw0sKkSAfUaPFrfpilhuQyUL8/EpF spclcYwOsVkuX5+i/sMHxXfc62ORyCTkFA6RXze3kBGe13XZWbw3mNKw8Fdwm/SnkhFl pnT6qOF0JtRbkvsmFFiVCqIQhBSbbjLP6u7rRBQZUZsTDsHeZ/EMDFkPlIR9RISuWAMt wow1ltyfu4d90Uq5JjH4BJUM6+rqlDRkj+ojI5p1V9STmBSII4WYQuj/ETJPhBynCXv+ Wh7g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oUt//bTkwsRrgK4y9pyKInt9C1fdhCh6LTSbXfNlTqo=; b=zfRqrKG8nPPhPW5dFZeCJ/8mF02SYxWmr6r43zVIM8kS7f4ztZdAdXL6QSFv16CzeF XiKXWb+V8yDe2sE+dSUXxEolbHPkc64I8qrKPyCMTJ2Q3GoxQNpLxEpOIH52awzdCxit 3i0SVg/zyuHHffFP5uf/h0ljIUbVxJRcxU0HahvdChQBZEdBBWFIE48qLJ6iIRR99zCe Pl+uUvYZjBCkyT3wg7wPoE/ITeYr/Y7R7wpbjYZl6+G2ISZMIMqxbTaLBbsbh4IGAyR6 kfH/VUjwe3iXAIc2DFlpjHK62mndmP1Df2+dwEB0srW96hb2B4Pnmnr7pGZmAShgVofn y3uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jzPfMtXi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qt10si10422661ejb.44.2020.11.18.06.41.35; Wed, 18 Nov 2020 06:41:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=jzPfMtXi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727010AbgKROht (ORCPT + 99 others); Wed, 18 Nov 2020 09:37:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbgKROhs (ORCPT ); Wed, 18 Nov 2020 09:37:48 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 812BBC0613D4; Wed, 18 Nov 2020 06:37:48 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id 1so2937935wme.3; Wed, 18 Nov 2020 06:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oUt//bTkwsRrgK4y9pyKInt9C1fdhCh6LTSbXfNlTqo=; b=jzPfMtXi3c3lf3x5WTV2VKBiyf3pBIUrqYGHGLm2s6bBxGPaCh1iYCYvnWhkAUjpU8 Zv8n70xpdmlaa5lm8wdSS3FKmpwU/BfbxDHm1UpZbNkccLLwaLZWFSPn8LmefP/6cQ7P 4x+Vq1JMNAbzDXE/O0/nmfPo8RSaZW8xSehCFifVrx3I8YLrbb9YzM1RqYtdXEWRg63b WzLWsyo7jSYPTSBuEEv9G1YPU5JipHH5T2fUUoFUH2Xhg4v8tfwDmHGNt7AhfP/S4kGw NiyB9PR1jnEo0NpYlbKTUAiS4SoP+qDwogpexp8w9jfFxEzREyfUFX5ji2UjO/5tNLWR gi8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oUt//bTkwsRrgK4y9pyKInt9C1fdhCh6LTSbXfNlTqo=; b=JmHKGMnEN8eXfDshFFt2vwueIWRdLomPE8LPQ9So/6eNfCgulXuJfelfWhx0HlipPV E9VLPqMUc2Mc4TzFzXO+yMeUPh23HTdSqixoW6Xa1aCFPpwJwn1k8KTeWYbXuc5p8lp3 kDQgIIpsuoxl+NSmSdwn8XYTuuLEAzsgKNID+DCTFByDBvjhrFuBBoNe/lRsCWk6ofBE sIlBhG1Efu3yruW7zApBKdR8bYYYRpARxwAqCqrikw4R8JquLOcUfh0okPOPhKhter4y Ve2YcCUI99TW0foLy4Cvl/ncs/Typk3Fm0404BSY6t2U5Oc1Fug/iHYZMwq5DUgUfzHK OQLQ== X-Gm-Message-State: AOAM531WjhKJKofYIDKC7QJ94jdCBgtMufCh0PyimM0e6gjdh8M645+s 5bvoZV1pqU4STT/5rYgIG5mhmDMmXFNmZQ== X-Received: by 2002:a1c:80c3:: with SMTP id b186mr385952wmd.20.1605710263838; Wed, 18 Nov 2020 06:37:43 -0800 (PST) Received: from localhost.localdomain (host-82-51-6-75.retail.telecomitalia.it. [82.51.6.75]) by smtp.gmail.com with ESMTPSA id w10sm34795307wra.34.2020.11.18.06.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 06:37:43 -0800 (PST) From: "Andrea Parri (Microsoft)" To: linux-kernel@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , linux-hyperv@vger.kernel.org, Michael Kelley , Juan Vazquez , Saruhan Karademir , "Andrea Parri (Microsoft)" Subject: [PATCH 3/6] Drivers: hv: vmbus: Avoid double fetch of payload_size in vmbus_on_msg_dpc() Date: Wed, 18 Nov 2020 15:36:46 +0100 Message-Id: <20201118143649.108465-4-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201118143649.108465-1-parri.andrea@gmail.com> References: <20201118143649.108465-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vmbus_on_msg_dpc() double fetches from payload_size. The double fetch can lead to a buffer overflow when (mem)copying the hv_message object. Avoid the double fetch by saving the value of payload_size into a local variable. Reported-by: Juan Vazquez Signed-off-by: Andrea Parri (Microsoft) --- drivers/hv/vmbus_drv.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 82b23baa446d7..0e39f1d6182e9 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1056,6 +1056,7 @@ void vmbus_on_msg_dpc(unsigned long data) void *page_addr = hv_cpu->synic_message_page; struct hv_message *msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; + __u8 payload_size = msg->header.payload_size; struct vmbus_channel_message_header *hdr; enum vmbus_channel_message_type msgtype; const struct vmbus_channel_message_table_entry *entry; @@ -1089,9 +1090,8 @@ void vmbus_on_msg_dpc(unsigned long data) goto msg_handled; } - if (msg->header.payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) { - WARN_ONCE(1, "payload size is too large (%d)\n", - msg->header.payload_size); + if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) { + WARN_ONCE(1, "payload size is too large (%d)\n", payload_size); goto msg_handled; } @@ -1100,21 +1100,18 @@ void vmbus_on_msg_dpc(unsigned long data) if (!entry->message_handler) goto msg_handled; - if (msg->header.payload_size < entry->min_payload_len) { - WARN_ONCE(1, "message too short: msgtype=%d len=%d\n", - msgtype, msg->header.payload_size); + if (payload_size < entry->min_payload_len) { + WARN_ONCE(1, "message too short: msgtype=%d len=%d\n", msgtype, payload_size); goto msg_handled; } if (entry->handler_type == VMHT_BLOCKING) { - ctx = kmalloc(sizeof(*ctx) + msg->header.payload_size, - GFP_ATOMIC); + ctx = kmalloc(sizeof(*ctx) + payload_size, GFP_ATOMIC); if (ctx == NULL) return; INIT_WORK(&ctx->work, vmbus_onmessage_work); - memcpy(&ctx->msg, msg, sizeof(msg->header) + - msg->header.payload_size); + memcpy(&ctx->msg, msg, sizeof(msg->header) + payload_size); /* * The host can generate a rescind message while we -- 2.25.1