From patchwork Wed Nov 18 15:33:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Parri X-Patchwork-Id: 11915355 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBEB8C6369E for ; Wed, 18 Nov 2020 15:33:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6637D2477C for ; Wed, 18 Nov 2020 15:33:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c4N9dhSe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbgKRPd3 (ORCPT ); Wed, 18 Nov 2020 10:33:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbgKRPd3 (ORCPT ); Wed, 18 Nov 2020 10:33:29 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDE7C0613D4; Wed, 18 Nov 2020 07:33:28 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id u12so2684130wrt.0; Wed, 18 Nov 2020 07:33:28 -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:mime-version :content-transfer-encoding; bh=8wny3kzVC1IR5EcyDuj2RgrjJgW1k6C8oLglaDehiy8=; b=c4N9dhSeYwm6VvvieK5qW8KPOFOb1Wz2H51Q7yNynXg8juBv//gERwBeLKzbwe7SYD gRYs8sJUqzU4fU1K9rptXIZ3eD4PSiDudVOWVfQazs2IK9r0SIO75oNldS19wvQNsen3 laZGh20fuAcG5rdpYNSDFevl0ku0DWv72c798Mp5s/GQKTUX2VvPqSLNdwsb2ata6Q4M +XIJk9GCoG9MK5W5+eF3WKSy8DK5YZ5r0ARcUYJc1Gn3NZ43JFYwDNKwlIvyY7PlZrzE RUYYUPg9YgAQvFDo2PA9GXRNBcD1x0Wv8N9h/5pvuf3DY1Eruu/VL24OEcbIIUCAtlGs U1cQ== 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:mime-version :content-transfer-encoding; bh=8wny3kzVC1IR5EcyDuj2RgrjJgW1k6C8oLglaDehiy8=; b=Oo0c10BkwxEHXeZRI4XVUxEv6G9PaehkXH/ENVdBmYGLRTa1k6NwWSC2M3r8SMIcSb GOu1uqvAYNBFecPHVHYOYGDxS9d1CP894xPyE4DB+r8OFJSODjYPjBNBYgHidLRo01hb WzrYmDEXPguopUnXwnSQtsJlO9N13vn0csag/VJPGmiVRRGQ1BW1UuT7847ACUROsuIr S5YCGbqDXsYh+bNLTWdcPdoe4E7Qt3KoKVoc7AkETiHlWmg0iFm5XfJW7Gky1c4kjyAN C4/iT0aM6xwEww2+AgBeXJwriI/nrsKOnxHp78ApZT2lJ563BGCv3lckhsmJflJ3iHHo pBXw== X-Gm-Message-State: AOAM5309lG8JUDzkQzNHm3mC0hXGi7/TCHIeaS9vR4NQnxcuJvcug7JU 9pnW3JYMdVNwc2DwvsVO1EpeBXOULzYMIC69 X-Google-Smtp-Source: ABdhPJz/vblUYoZh2K8DlxwaydB+cG/5byw4frw9B7T+IEsnhSzf5xXi92WJfR2i2m98L3GIwyJlQQ== X-Received: by 2002:a5d:6447:: with SMTP id d7mr5525080wrw.96.1605713607160; Wed, 18 Nov 2020 07:33:27 -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 v19sm4394146wmj.31.2020.11.18.07.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 07:33:26 -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)" , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH] hv_netvsc: Validate number of allocated sub-channels Date: Wed, 18 Nov 2020 16:33:10 +0100 Message-Id: <20201118153310.112404-1-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Lack of validation could lead to out-of-bound reads and information leaks (cf. usage of nvdev->chan_table[]). Check that the number of allocated sub-channels fits into the expected range. Suggested-by: Saruhan Karademir Signed-off-by: Andrea Parri (Microsoft) Cc: "David S. Miller" Cc: Jakub Kicinski Cc: netdev@vger.kernel.org Reviewed-by: Haiyang Zhang Acked-by: Jakub Kicinski Reviewed-by: Michael Kelley --- Based on hyperv-next. drivers/net/hyperv/rndis_filter.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c index 3835d9bea1005..c5a709f67870f 100644 --- a/drivers/net/hyperv/rndis_filter.c +++ b/drivers/net/hyperv/rndis_filter.c @@ -1226,6 +1226,11 @@ int rndis_set_subchannel(struct net_device *ndev, return -EIO; } + /* Check that number of allocated sub channel is within the expected range */ + if (init_packet->msg.v5_msg.subchn_comp.num_subchannels > nvdev->num_chn - 1) { + netdev_err(ndev, "invalid number of allocated sub channel\n"); + return -EINVAL; + } nvdev->num_chn = 1 + init_packet->msg.v5_msg.subchn_comp.num_subchannels;