Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp870215ybt; Fri, 10 Jul 2020 14:48:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOKOYxyQtuPx8DekITzTYzdDzjCS4fLOYM1Lx/5hGBEgfkS2YHR0WQ7De+5G09ralEQo0v X-Received: by 2002:aa7:d989:: with SMTP id u9mr61857162eds.85.1594417689671; Fri, 10 Jul 2020 14:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594417689; cv=none; d=google.com; s=arc-20160816; b=Bj3aSgWD9tyQhaNxuAfFsBGUO5F+mkjVncCFa5ByWjTLanG1748MucSVQkZ+6/q6BC 0Xt20aRkJGxqtJFbz0VY/TYjQrOirBLJ8Gcjlchc1XEiyz1u5wlXUfnpPnvI4pDswYTS bBzdzXMtf9QynPF/+Z2s965hci3Qqg5d6lZBzXA6Iw+pjJH1AnD2/JsXaNV//Q4yG9Bq lp1MJQwykt4Ml9V6IoS0oYRtMwzUdsSG9e3/ZAIHBiYMy8xqSmKjcsR3a8SsabL5tCQR 6ubVf2WPWT3+YclCjXp5ke2Ap6cUB7OAGXXwN/azUXmMvQMJ5QjTnxLJz7n34YfgzLa3 UGFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H4BIXM/X/4TDwBaDfHH2qeLVBAs7PCGQrZDucm3WMQA=; b=zF+HXphbRCChJPbmkGvXFPrMF2PY1VHRIwZay42f+lVPoYz2NYYXpTysNhRRnucRXc vjeY/nnQlredzF1+ZHeAK5EyJ8QL196pjigJSE0hUeQ9jTsUpgJ5+IqMIF3IccSwjnNX jRf5DL7SMJbJcYR6xiIlNFgbwGmRtBqhXSeaE7mGgz1f6ljTngGdDHBu4yeW5HukACg0 sH/QPWrmsCXV5u4Dx1zBydnKZ5mZ1MZSsZSqM7/VdlESNZAifpYov7noZ1PLmJx9nY+3 EpQ4vEGawxL13fy7zox3tRycx+ff2+g4V2a+0P3r9fxRNHMYYvFdmb9batWtBnLUvIvn M6AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lXA0dnkh; 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 h13si4824669ejl.692.2020.07.10.14.47.46; Fri, 10 Jul 2020 14:48:09 -0700 (PDT) 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=lXA0dnkh; 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 S1726519AbgGJVrZ (ORCPT + 99 others); Fri, 10 Jul 2020 17:47:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbgGJVrZ (ORCPT ); Fri, 10 Jul 2020 17:47:25 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BA0BC08C5DC; Fri, 10 Jul 2020 14:47:25 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id a14so3294100qvq.6; Fri, 10 Jul 2020 14:47:25 -0700 (PDT) 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=H4BIXM/X/4TDwBaDfHH2qeLVBAs7PCGQrZDucm3WMQA=; b=lXA0dnkhWEzo+ZcE67jH+G1OgotEBlFxSKDTrTSdVqYCG25rP2YQDQjX8ZX2ow1Q1/ XlzIEgUG9K6iyMLvNZFTuxDS7VSBtmGBdcVsjPM+2I8UX3K5VAsatr9rnxB9FfBvjsJq hABIVqaZYYjcKtikl3YtQSstw1Iv512kGKS/L21/Yro9jRmyD8t/OtRiByiwvlFiixgz 9C1CnWBNmZQfAm3+g2JVCaxPmzfqZIPr2DvRSCA3EonhzUW4Z3W1oS46s/06jAky2TW1 IH0hvL3WhTD98VFnr3vKykPgI2eZVcLjZz8PgsVx1H7itedHXLhQm2hRbCUkxOqFFFll 6KaA== 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=H4BIXM/X/4TDwBaDfHH2qeLVBAs7PCGQrZDucm3WMQA=; b=UyFu8h6Y7gp8UktsR9xP2HnmBHHEITCOT5ivZ1aFfuvLQg/bQmpDf4KQCisW8kM+KN UGrbh42GqOjXrvE0TYku82v9qB/vhTLN8vq7q3RxUYTlBLYEFaNuxQfe5OeXlrVaNDH4 3izTCPBbYPz38aXUABKBfz4Qyy5KPjU/iWM810WRt8JsRwrYxEJmKglYGGvBbnuDeoK8 kn6gW1jSQYyDpvL6avbD+8ofxdp3ibj1i7PPi0AqPgFyAvIPCBA9ozIveZeBYoT3bQoC clYR5d0hgN/aKGSNiiRPbTTX1ptnkN6oh0CDd0ruV6LW1Gq9flIN+rCg4wP0hEdV4A4w n6xg== X-Gm-Message-State: AOAM532170PK2l+vuyoXpM1AilKWqKowti22fmSXjB1dhOTNYPw9343Q 1ES3DSVmIg6PQ5eDBcjHKw== X-Received: by 2002:a0c:f109:: with SMTP id i9mr66510402qvl.154.1594417644040; Fri, 10 Jul 2020 14:47:24 -0700 (PDT) Received: from localhost.localdomain (c-76-119-149-155.hsd1.ma.comcast.net. [76.119.149.155]) by smtp.gmail.com with ESMTPSA id p66sm8930426qkf.58.2020.07.10.14.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 14:47:23 -0700 (PDT) From: Peilin Ye To: Marcel Holtmann , Johan Hedberg Cc: Peilin Ye , "David S . Miller" , Jakub Kicinski , Russell King , Greg KH , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [Linux-kernel-mentees] [PATCH 2/2] net/bluetooth: Prevent out-of-bounds read in hci_inquiry_result_with_rssi_evt() Date: Fri, 10 Jul 2020 17:45:26 -0400 Message-Id: <82c4e719b7615f5333444bdc2b5cc243a693eeb1.1594414498.git.yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <3f69f09d6eb0bc1430cae2894c635252a1cb09e1.1594414498.git.yepeilin.cs@gmail.com> References: <3f69f09d6eb0bc1430cae2894c635252a1cb09e1.1594414498.git.yepeilin.cs@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check `num_rsp` before using it as for-loop counter. Add `unlock` label. Cc: stable@vger.kernel.org Signed-off-by: Peilin Ye --- net/bluetooth/hci_event.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 8b3736c83b8e..f9f4262414b3 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4159,6 +4159,9 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct inquiry_info_with_rssi_and_pscan_mode *info; info = (void *) (skb->data + 1); + if (skb->len < num_rsp * sizeof(*info) + 1) + goto unlock; + for (; num_rsp; num_rsp--, info++) { u32 flags; @@ -4180,6 +4183,9 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, } else { struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); + if (skb->len < num_rsp * sizeof(*info) + 1) + goto unlock; + for (; num_rsp; num_rsp--, info++) { u32 flags; @@ -4200,6 +4206,7 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, } } +unlock: hci_dev_unlock(hdev); } -- 2.25.1