Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1429740imb; Sat, 2 Mar 2019 15:18:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzBUYnbel2x85raWptsfHQF+6a/RZW07z6Bj/RE55mSvKofVXdytBXvRFELfLJcLhhdSwlQ X-Received: by 2002:a17:902:bd43:: with SMTP id b3mr12953535plx.186.1551568721688; Sat, 02 Mar 2019 15:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551568721; cv=none; d=google.com; s=arc-20160816; b=HTdr6/bit/8G0QMBq9Sl8KLLDL2bq3xXLnpq27Kq1t7k7u9GMaFaaCTt7biBZhCDXt dO74yYC5zJXsK3Fr1hfJ6cSycw5ukbZCV4ccQvB8eiENLt6qjHKgFi64Ye0mPvtfLSZa x61Zr6SGqH9CYE9UlPLwPWGsOft/GpEPlE1zcuDEsuUkyIj11Yw/uhh7aDtIMd5MIbxP Ppur3+yMNhpHoLPJHF27+QONevGhMtYwJLBEXuM2nQlqbkvk3YOA86pUPD9BTt5kTj4D vIUP05wd/jVqcyvgU5qQ/gR+4tj33UsBAOncYBZmMIBNaOxDYk3tdYNJLCa5+vk0KpJx z+8Q== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=M7jIS//rCFk++6S+n9FbGOLmMxyBmtUuiNkz8k3ERNI=; b=xo089KpQ34JlMNkwQHdut9e+Ie10kXOYAVomtnSViW9UBDCRz6ATfaBF4HHs0P9Kfa 8WMHIdqKMmFafG1YIQ/mlHGqb1U70j+O5yibWVbofBNV+dn/j4G13iiGZq4CyHTMEwjR V46dVSlKosO5RrPlOmkJH38jDGq6mcSBeL3KCxAGaCc1r/aWHpn9c4GvuSQoXoQEK5/W p7hWIieRfkdt+RsYaq9+3ieUifmTM9JykvtuAopnauiRpjvReQquVpEkFephMOoW7OO6 DXhfiHtm9rJVTsRl6+7t31bzCEwypOEUAIhXdMTGOYkYe8scZl50c9XCZFUXkAuC8+mX xijg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Abrpzevq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id v4si1531635pff.172.2019.03.02.15.18.23; Sat, 02 Mar 2019 15:18:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Abrpzevq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726830AbfCBXSC (ORCPT + 99 others); Sat, 2 Mar 2019 18:18:02 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44516 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726529AbfCBXSB (ORCPT ); Sat, 2 Mar 2019 18:18:01 -0500 Received: by mail-lf1-f67.google.com with SMTP id v185so968620lfa.11; Sat, 02 Mar 2019 15:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=M7jIS//rCFk++6S+n9FbGOLmMxyBmtUuiNkz8k3ERNI=; b=Abrpzevqkb0f+/AfOwX1FxtVnrpAd7vCQKTtSelCMFhfXLNXnAZefAF7mOmwZFb84c dbSafENlxohFXAh6RoMlCQt49domF5Ms0w4ymUiIZlmEXa0hTLBQlTs+mK/IJ8UKNlTD USkBDlxmcGXRIlIomBUf7QNt8fXe2TW0CY7irBDXLvsbW75yp6BSUGxAgQIk8s4Hj39n F9YQkF0M3ACP4YXX0vFs7ODVPyV1VoG/UqqRB0FtK+rUiSI120+PDnhTGMwA9eKUxyAl xzLhV/yAuh18svDbV9NvkOFwg9PD9gR8QNTChbTMWOe6MOSWQfwwzqPmyZVkktkvOuNY MKLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=M7jIS//rCFk++6S+n9FbGOLmMxyBmtUuiNkz8k3ERNI=; b=n55t0ccYJATg264+08yRZo/Apsj6gSY/DXreVr9iKp9dDGLo44pocMecqqDYU+l5IP en5vvE4+v5eYsMxhPsdbsIBDa+ddpE07p725+XRFydG01YqgwoLZ2k66xx/ODKQ1N14O YZQnH14aBp8WT8w9SbNFni/1m0UmVjTaqNMaOo8XBtJvHEIJRPlWUWY8rhD6GG4HJTYo xjoHf+/ovH8YHB3C609fMRPQAMd0iVAa0pBddDWmqvd0Hlx0I7W27BhX2KIa1h1UgdlB N49KTNQ2zDWciEfMENAwW/EgkgKfzVW33iRQd89m8OMvtSTBED0lY8u7UiRnH5DgghI8 ejrw== X-Gm-Message-State: APjAAAUGDWIj4kQI8aSgnbxXHCv+5CpPMh31lIQO9M7MgfC4eXUx79jw UwzMSJey07GghzDUl3XGs30= X-Received: by 2002:ac2:559b:: with SMTP id v27mr6477439lfg.164.1551568678202; Sat, 02 Mar 2019 15:17:58 -0800 (PST) Received: from ?IPv6:2a02:aa7:4000:561e:3eff:d48d:3612:5c09? ([2a02:aa7:4000:561e:3eff:d48d:3612:5c09]) by smtp.gmail.com with ESMTPSA id m16sm481575ljb.50.2019.03.02.15.17.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 15:17:57 -0800 (PST) Subject: Re: [PATCH] net/bluetooth: Fix bound check in event handling To: Marcel Holtmann Cc: Johan Hedberg , "David S. Miller" , "open list:BLUETOOTH DRIVERS" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com References: <20190228195939.30685-1-tomasbortoli@gmail.com> <8F6AC5BF-F50B-4C30-A73B-98526AF181EB@holtmann.org> From: Tomas Bortoli Openpgp: preference=signencrypt Autocrypt: addr=tomasbortoli@gmail.com; prefer-encrypt=mutual; keydata= mQINBFpCTZMBEADNZ1+Ibh0Z4pgGRcd1aOUMbe/YfHktmajjcoTnKmZZunjoUVAl8waeLITd BC2c8i1wHzHcnthrmb1izs5XlG6PZnl8n5tjysSNbwggzS1NcEK1qgn5VjNlHQ5aRMUwCC51 kicBiNmlQk2UuzzWwdheRGnaf+O1MNhC0GBeEDKQAL5obOU92pzflv6wWNACr+lHxdnpyies mOnRMjH16NjuTkrGbEmJe+MKp0qbjvR3R/dmFC1wczniRMQmV5w3MZ/N9wRappE+Atc1fOM+ wP7AWNuPvrKg4bN5uqKZLDFH7OFpxvjgVdWM40n0cQfqElWY9as+228Sltdd1XyHtUWRF2VW O1l5L0kX0+7+B5k/fpLhXqD3Z7DK7wRXpXmY59pofk7aFdcN97ZK+r6R7mqrwX4W9IpsPhkT kUyg3/Dx/khBZlJKFoUP325/hoH684bSiPEBroel9alB7gTq2ueoFwy6R3q5CMUw3D+CZWHA 3xllu46TRQ/Vt2g0cIHQNPoye2OWYFJ6kSEvaLpymjNDJ9ph2EuHegonDfOaYSq34ic2BcdB JkCgXRLP5K7KtRNJqqR+DM8xByeGmQv9yp6S97el+SiM9R53RhHawJZGz0EPl+2Q6+5mgh3u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2+PM5I0xebbxtnuTewRchVVfm7UWgLAy11pV3xM4wMSJOuqVMOz jYpWKYxDTpvsZ0ginUUY993Gb8k/CxjABEMUGVHhQPZ0OzjHIKS6cTzN6ue8bB+CGOLCaQp1 C0NRT5Tn9zpLxtf5nBExFd/zVENY5vAV2ZbKQdemO54O7j6B9DSgVRrm83GCZxbL4d+qTYBF 3tSCWw/6SG1F3q9gR9QrSC2YRjCmhijUVEh6FhZwB58TNZ1sEEttrps8TDa5tUd9 Message-ID: <0b49ec72-b8a6-8631-e21d-9efd30354e1d@gmail.com> Date: Sun, 3 Mar 2019 00:17:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <8F6AC5BF-F50B-4C30-A73B-98526AF181EB@holtmann.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marcel, On 3/2/19 5:46 PM, Marcel Holtmann wrote: > Hi Tomas, > >> hci_inquiry_result_with_rssi_evt() can perform out of bound reads >> on skb->data as a bound check is missing. >> >> Signed-off-by: Tomas Bortoli >> Reported-by: syzbot+cec7a50c412a2c03f8f5@syzkaller.appspotmail.com >> Reported-by: syzbot+660883c56e2fa65d4497@syzkaller.appspotmail.com >> --- >> Syzkaler reports: >> https://syzkaller.appspot.com/bug?id=d708485af9edc3af35f3b4d554e827c6c8bf6b0f >> https://syzkaller.appspot.com/bug?id=3acd1155d48a5acc5d76711568b04926945a6885 >> >> net/bluetooth/hci_event.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c >> index ac2826ce162b..aa953d23bb72 100644 >> --- a/net/bluetooth/hci_event.c >> +++ b/net/bluetooth/hci_event.c >> @@ -3983,6 +3983,10 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, >> for (; num_rsp; num_rsp--, info++) { >> u32 flags; >> >> + if ((void *)(info + sizeof(info)) > >> + (void *)(skb->data + skb->len)) >> + break; >> + > > first of all, the loop exists twice here. If one is vulnerable, then the second is a well. And second, can we not just do this inside the for-condition check or a lot simpler than this void casting fun. > 1. The other for loop is not vulnerable because of the `if` that wraps the loops. Unfortunately the condition only provides bound checking for the "else" branch. 2. Sure. I was just getting some compiler warning like "calculated value but unused" when putting the additional condition. By the way I am curious to see how to avoid this void casting. Regards, Tomas