From patchwork Wed Oct 9 17:41:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 834126 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 774441E1A1C for ; Wed, 9 Oct 2024 17:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728495726; cv=none; b=DGw/5Glu3K0SLqIEnnL4TocWfIepksfxvB5pA442bQODvL/1XdyTOcHU/PaKzcrkt7ZG3CCTkQsxCZFse6YLRSx2wJSVxla//nweUH2UobXcQCqusZskfEyQeE9fu/UsB7cGL74zd+gtgktQZWOmo+hXTep+efkDtUPzZlYYiSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728495726; c=relaxed/simple; bh=EKKtXBmbTsgg5aJfG+bqnKrO3lF5cL6lJybtQvaFXls=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ajL0xlxvc5sSmGJ3p35rL4Q/J6Mjz+iGATQjQd1UUQ92AfzWdgYUt2OIxXqSXJYZ2uZahZy4EfSr5Nfh1FVpZiY/PNH4UKVC4c0/Xl/ptHvFaVyEaWHJyr8+Z4v6GDi5e88cLPguvmq4ut0IZUeRkh2pqYbd4D42RVkW9amwi/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J9o7avNo; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J9o7avNo" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e28ea358f65so93934276.0 for ; Wed, 09 Oct 2024 10:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728495723; x=1729100523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=KK9o9FLLSOpGDDJwgR8CE1uDvUbDAUP113jniXxEl8w=; b=J9o7avNopQv4zc4jWk7qwBPXw4Y/il0AKc94lJVAJtGY6M/RxP8SXY6KSeAS4/kK55 VEHzYIgP1wqC2mtabD7GQNsFrl47KJFQdyxsnQ6wFDkOttULaziievGADZTxT4tgjSz7 rpZl9EvofInrLZXwIIL2mcaG+f5IasJkQikFs0Fsj89p9/ShQhSl4OQGXzM77k+0KXby ax/PzUfYVgJpL26fzI1Agy3QIApba/65HElEH/S2l4LQFXahEuhHVy34ZlUJ6M9wY3lm FeKytFV2QZI5KAss+HjZMelvAuUTs260qvreLd3OPW5y5zoJxz+F6FW8SchAh+xHhfb+ LaEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728495723; x=1729100523; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KK9o9FLLSOpGDDJwgR8CE1uDvUbDAUP113jniXxEl8w=; b=mlz8C0cnrhBBYJ1uIKhildmajaDkvw8IDoGdqsopt5kEMomKMfDkkQ3Q8c4xXKCZWJ b93hiV3XIms74gL1mVG+u9F208GqaP2PjMLAyoIyXIUEeq+SUlqBKpW0sw3847yUoB8H W3ysfsGknbX9KJqJLGP4geuanHi6ia/97QZnYQGz5BEwBJMpXqG7hTfaudvdlhQnuRLz mC1NuuxIzo8l4/D8JaBsIHl2V6yk8TwSWDbzYQLgbuPH6qAfmqIHN4sDrY0XzQBYPTZ7 Dtr0QByjnJ4kXsXcMeAQaSPtaPLKLGxqgLTWxHQ+ZIZcl1VDASsYHY8wf4JLF49Skmxe dLZA== X-Gm-Message-State: AOJu0YyL5EsNPUzgO3W+mRmsejPr334v20R9B/GyVqrfBW2kKJhUN9dE +8o05Cp3BShs+O7eOOa9kzNqF2Q5PMCGSmaG1y57mSw4Zr+AzPHXTDQbcgcY X-Google-Smtp-Source: AGHT+IFVNxhjo+4+n9Di826hZUZHxmgmh5g9ZfELlKI72Fy/9IYUWmk/UKkSYp8YFNFWU02dhtCm2g== X-Received: by 2002:a05:6902:114c:b0:e28:e4d8:f6ac with SMTP id 3f1490d57ef6-e290b7eb2b0mr516539276.17.1728495722707; Wed, 09 Oct 2024 10:42:02 -0700 (PDT) Received: from lvondent-mobl5.safetynetaccess.com ([50.204.57.18]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e28a5c3755fsm1850405276.17.2024.10.09.10.42.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:42:00 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet Date: Wed, 9 Oct 2024 13:41:58 -0400 Message-ID: <20241009174159.15658-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.46.2 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This fixes not checking if skb really contains an ACL header otherwise the code may attempt to access some uninitilized/invalid memory past the valid skb->data. Reported-by: syzbot+6ea290ba76d8c1eb1ac2@syzkaller.appspotmail.com Tested-by: syzbot+6ea290ba76d8c1eb1ac2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6ea290ba76d8c1eb1ac2 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index b2f8f9c5b610..d5f917076e0e 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3765,18 +3765,22 @@ static void hci_tx_work(struct work_struct *work) /* ACL data packet */ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) { - struct hci_acl_hdr *hdr = (void *) skb->data; + struct hci_acl_hdr *hdr; struct hci_conn *conn; __u16 handle, flags; - skb_pull(skb, HCI_ACL_HDR_SIZE); + hdr = skb_pull_data(skb, sizeof(*hdr)); + if (!hdr) { + bt_dev_err(hdev, "ACL packet too small"); + goto drop; + } handle = __le16_to_cpu(hdr->handle); flags = hci_flags(handle); handle = hci_handle(handle); - BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, - handle, flags); + bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, + handle, flags); hdev->stat.acl_rx++; @@ -3797,6 +3801,7 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) handle); } +drop: kfree_skb(skb); } From patchwork Wed Oct 9 17:41:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 834970 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 652941E0E16 for ; Wed, 9 Oct 2024 17:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728495727; cv=none; b=mX7ciQx3kQ3iH0jvwRxfv9QaO6k0an01MxD1U9e/SD822f7cZ/NuW9QQaVv/SdnKgXfhgvUy47HcfF3c+qG57JqOHF4OY8LPT5DiZ1ELJa/YDf6e07fHbRQX6YCspE4dsPok1WSEtjOXxGGEhICpsaL1xbBGENB3KKxrccE69XQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728495727; c=relaxed/simple; bh=mKRaqqrTDqsjJiGT5HqYOVAvwqO16cHV5uyotgYW5ww=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZrjPkfm2Iv8KW9lQvHSNd8UdEkBUk8jjMIo5jQAZW7ADzRCX5WCpkLYDDR4ooxYl/tloGt6XnxkW35nrOraa05hbvZJTv650nqG3ftD8Lu9QhGKlkbY/c3ZSFHdmZHpZ+BymadDAHdALRr+dvA+bT9cjBzL+1T8tC4RqEOVdV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lwm03hC0; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lwm03hC0" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e2908e8d45eso451648276.2 for ; Wed, 09 Oct 2024 10:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728495725; x=1729100525; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SYNUEVyY6t3O86bI0XZXWo8P5jtZ/LYl1bjt0nJaaBQ=; b=lwm03hC0Z7KtKH7tlR6262SSkuZCgrA30gUh+SvYtV34C9oo7tXgL+GjCcZ1c+TrbQ AQtKOaUVThso+VC7uteSQXzhFLkMMVr/UUpAxBDkvot+g9Ew2MOvUVG2rRZuzcmjtivF uwWoEZMGBTmHdSCj5ulVkQgXGqlkQOumIP+ArzTKdyZxsbVW76WDVJzoe4z2qbMTMMqf nV9geZgdtS7XzHY07fcLxWCKFZ+XGzEblql8hISAmff5yCYpBUcMQmBdl2L5H0W1zB95 J2vBtb4ApkgzSVIzaoaYFifTRzXYPrl2EHjj6HRTdHk+CZwUGjM+a+TD6rVa5S4cSDqx 9S2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728495725; x=1729100525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SYNUEVyY6t3O86bI0XZXWo8P5jtZ/LYl1bjt0nJaaBQ=; b=AC/+P7bhK3PenyOvZzTqBggS0qM6I8JmjU10y3qVJpVb+mPDUCtDffr+DED3pmn2YF dSRuuMOZEITI82tr9pyQN0p3GgCcwQNZG3c7OnXP/C5GD2K+vNj78MokRlNZQJy9kkRl 98fXSMNtO62XbssNwzzwcuPdj40EmULeo2CheBKaBVIJkh3RfvNBiVOLjON95GRc2BOL ZfKKaLqI3AIReHA28wH8ad0zQ1JipjSbK0Wy7EO9mMblh213if98VkJ9m6kJ38sxsMeQ kwXZ9NbWakEeS7a/jEoKPilfMOBttucwpfc0P5LbH6l7Q+sYs/N3so7RVduETnRFXxi2 Mbcw== X-Gm-Message-State: AOJu0YwH3jn35bo0dJyyB1OoagC42nr7ZlX4rmulNQau+mUidd0+t2gL bjtOpr8SRPU/HvOJx+KxfaylBZKO9us7qP2OOrVTVW0dgZ64pzK86cOoWWDs X-Google-Smtp-Source: AGHT+IGo3kECjQ6tEDcHTOMp+fHt9kwSsyPd8ZyHIQyJywQhQ5wMPo6jRgcTHlVYgSelE3oF01cnGg== X-Received: by 2002:a05:6902:c03:b0:e28:eaed:3244 with SMTP id 3f1490d57ef6-e28fe420229mr2090403276.55.1728495724593; Wed, 09 Oct 2024 10:42:04 -0700 (PDT) Received: from lvondent-mobl5.safetynetaccess.com ([50.204.57.18]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e28a5c3755fsm1850405276.17.2024.10.09.10.42.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 10:42:03 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 2/2] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet Date: Wed, 9 Oct 2024 13:41:59 -0400 Message-ID: <20241009174159.15658-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241009174159.15658-1-luiz.dentz@gmail.com> References: <20241009174159.15658-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This fixes not checking if skb really contains an SCO header otherwise the code may attempt to access some uninitilized/invalid memory past the valid skb->data. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index d5f917076e0e..779c4aeaef22 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3808,18 +3808,22 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) /* SCO data packet */ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) { - struct hci_sco_hdr *hdr = (void *) skb->data; + struct hci_sco_hdr *hdr; struct hci_conn *conn; __u16 handle, flags; - skb_pull(skb, HCI_SCO_HDR_SIZE); + hdr = skb_pull_data(skb, sizeof(*hdr)); + if (!hdr) { + bt_dev_err(hdev, "SCO packet too small"); + goto drop; + } handle = __le16_to_cpu(hdr->handle); flags = hci_flags(handle); handle = hci_handle(handle); - BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, - handle, flags); + bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, + handle, flags); hdev->stat.sco_rx++; @@ -3837,6 +3841,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) handle); } +drop: kfree_skb(skb); }