From f2d33b30fbb887999c21be62a918e81ff48b6cee Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 5 Apr 2024 09:06:13 +0200 Subject: [PATCH] 4.19-stable patches added patches: bluetooth-fix-toctou-in-hci-debugfs-implementation.patch bluetooth-hci_event-set-the-conn-encrypted-before-conn-establishes.patch net-rds-fix-possible-cp-null-dereference.patch netfilter-nf_tables-disallow-timeout-for-anonymous-sets.patch r8169-fix-issue-caused-by-buggy-bios-on-certain-boards-with-rtl8168d.patch --- ...toctou-in-hci-debugfs-implementation.patch | 192 ++++++++++++++++++ ...nn-encrypted-before-conn-establishes.patch | 108 ++++++++++ ...rds-fix-possible-cp-null-dereference.patch | 66 ++++++ ...-disallow-timeout-for-anonymous-sets.patch | 43 ++++ ...bios-on-certain-boards-with-rtl8168d.patch | 43 ++++ queue-4.19/series | 5 + 6 files changed, 457 insertions(+) create mode 100644 queue-4.19/bluetooth-fix-toctou-in-hci-debugfs-implementation.patch create mode 100644 queue-4.19/bluetooth-hci_event-set-the-conn-encrypted-before-conn-establishes.patch create mode 100644 queue-4.19/net-rds-fix-possible-cp-null-dereference.patch create mode 100644 queue-4.19/netfilter-nf_tables-disallow-timeout-for-anonymous-sets.patch create mode 100644 queue-4.19/r8169-fix-issue-caused-by-buggy-bios-on-certain-boards-with-rtl8168d.patch diff --git a/queue-4.19/bluetooth-fix-toctou-in-hci-debugfs-implementation.patch b/queue-4.19/bluetooth-fix-toctou-in-hci-debugfs-implementation.patch new file mode 100644 index 00000000000..f38548b609f --- /dev/null +++ b/queue-4.19/bluetooth-fix-toctou-in-hci-debugfs-implementation.patch @@ -0,0 +1,192 @@ +From 7835fcfd132eb88b87e8eb901f88436f63ab60f7 Mon Sep 17 00:00:00 2001 +From: Bastien Nocera +Date: Wed, 27 Mar 2024 15:24:56 +0100 +Subject: Bluetooth: Fix TOCTOU in HCI debugfs implementation + +From: Bastien Nocera + +commit 7835fcfd132eb88b87e8eb901f88436f63ab60f7 upstream. + +struct hci_dev members conn_info_max_age, conn_info_min_age, +le_conn_max_interval, le_conn_min_interval, le_adv_max_interval, +and le_adv_min_interval can be modified from the HCI core code, as well +through debugfs. + +The debugfs implementation, that's only available to privileged users, +will check for boundaries, making sure that the minimum value being set +is strictly above the maximum value that already exists, and vice-versa. + +However, as both minimum and maximum values can be changed concurrently +to us modifying them, we need to make sure that the value we check is +the value we end up using. + +For example, with ->conn_info_max_age set to 10, conn_info_min_age_set() +gets called from vfs handlers to set conn_info_min_age to 8. + +In conn_info_min_age_set(), this goes through: + if (val == 0 || val > hdev->conn_info_max_age) + return -EINVAL; + +Concurrently, conn_info_max_age_set() gets called to set to set the +conn_info_max_age to 7: + if (val == 0 || val > hdev->conn_info_max_age) + return -EINVAL; +That check will also pass because we used the old value (10) for +conn_info_max_age. + +After those checks that both passed, the struct hci_dev access +is mutex-locked, disabling concurrent access, but that does not matter +because the invalid value checks both passed, and we'll end up with +conn_info_min_age = 8 and conn_info_max_age = 7 + +To fix this problem, we need to lock the structure access before so the +check and assignment are not interrupted. + +This fix was originally devised by the BassCheck[1] team, and +considered the problem to be an atomicity one. This isn't the case as +there aren't any concerns about the variable changing while we check it, +but rather after we check it parallel to another change. + +This patch fixes CVE-2024-24858 and CVE-2024-24857. + +[1] https://sites.google.com/view/basscheck/ + +Co-developed-by: Gui-Dong Han <2045gemini@gmail.com> +Signed-off-by: Gui-Dong Han <2045gemini@gmail.com> +Link: https://lore.kernel.org/linux-bluetooth/20231222161317.6255-1-2045gemini@gmail.com/ +Link: https://nvd.nist.gov/vuln/detail/CVE-2024-24858 +Link: https://lore.kernel.org/linux-bluetooth/20231222162931.6553-1-2045gemini@gmail.com/ +Link: https://lore.kernel.org/linux-bluetooth/20231222162310.6461-1-2045gemini@gmail.com/ +Link: https://nvd.nist.gov/vuln/detail/CVE-2024-24857 +Fixes: 31ad169148df ("Bluetooth: Add conn info lifetime parameters to debugfs") +Fixes: 729a1051da6f ("Bluetooth: Expose default LE advertising interval via debugfs") +Fixes: 71c3b60ec6d2 ("Bluetooth: Move BR/EDR debugfs file creation into hci_debugfs.c") +Signed-off-by: Bastien Nocera +Signed-off-by: Luiz Augusto von Dentz +Signed-off-by: Greg Kroah-Hartman +--- + net/bluetooth/hci_debugfs.c | 48 +++++++++++++++++++++++++++++--------------- + 1 file changed, 32 insertions(+), 16 deletions(-) + +--- a/net/bluetooth/hci_debugfs.c ++++ b/net/bluetooth/hci_debugfs.c +@@ -200,10 +200,12 @@ static int conn_info_min_age_set(void *d + { + struct hci_dev *hdev = data; + +- if (val == 0 || val > hdev->conn_info_max_age) ++ hci_dev_lock(hdev); ++ if (val == 0 || val > hdev->conn_info_max_age) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->conn_info_min_age = val; + hci_dev_unlock(hdev); + +@@ -228,10 +230,12 @@ static int conn_info_max_age_set(void *d + { + struct hci_dev *hdev = data; + +- if (val == 0 || val < hdev->conn_info_min_age) ++ hci_dev_lock(hdev); ++ if (val == 0 || val < hdev->conn_info_min_age) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->conn_info_max_age = val; + hci_dev_unlock(hdev); + +@@ -479,10 +483,12 @@ static int sniff_min_interval_set(void * + { + struct hci_dev *hdev = data; + +- if (val == 0 || val % 2 || val > hdev->sniff_max_interval) ++ hci_dev_lock(hdev); ++ if (val == 0 || val % 2 || val > hdev->sniff_max_interval) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->sniff_min_interval = val; + hci_dev_unlock(hdev); + +@@ -507,10 +513,12 @@ static int sniff_max_interval_set(void * + { + struct hci_dev *hdev = data; + +- if (val == 0 || val % 2 || val < hdev->sniff_min_interval) ++ hci_dev_lock(hdev); ++ if (val == 0 || val % 2 || val < hdev->sniff_min_interval) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->sniff_max_interval = val; + hci_dev_unlock(hdev); + +@@ -749,10 +757,12 @@ static int conn_min_interval_set(void *d + { + struct hci_dev *hdev = data; + +- if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval) ++ hci_dev_lock(hdev); ++ if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->le_conn_min_interval = val; + hci_dev_unlock(hdev); + +@@ -777,10 +787,12 @@ static int conn_max_interval_set(void *d + { + struct hci_dev *hdev = data; + +- if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval) ++ hci_dev_lock(hdev); ++ if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->le_conn_max_interval = val; + hci_dev_unlock(hdev); + +@@ -889,10 +901,12 @@ static int adv_min_interval_set(void *da + { + struct hci_dev *hdev = data; + +- if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval) ++ hci_dev_lock(hdev); ++ if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->le_adv_min_interval = val; + hci_dev_unlock(hdev); + +@@ -917,10 +931,12 @@ static int adv_max_interval_set(void *da + { + struct hci_dev *hdev = data; + +- if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval) ++ hci_dev_lock(hdev); ++ if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval) { ++ hci_dev_unlock(hdev); + return -EINVAL; ++ } + +- hci_dev_lock(hdev); + hdev->le_adv_max_interval = val; + hci_dev_unlock(hdev); + diff --git a/queue-4.19/bluetooth-hci_event-set-the-conn-encrypted-before-conn-establishes.patch b/queue-4.19/bluetooth-hci_event-set-the-conn-encrypted-before-conn-establishes.patch new file mode 100644 index 00000000000..94632215983 --- /dev/null +++ b/queue-4.19/bluetooth-hci_event-set-the-conn-encrypted-before-conn-establishes.patch @@ -0,0 +1,108 @@ +From c569242cd49287d53b73a94233db40097d838535 Mon Sep 17 00:00:00 2001 +From: Hui Wang +Date: Wed, 27 Mar 2024 12:30:30 +0800 +Subject: Bluetooth: hci_event: set the conn encrypted before conn establishes + +From: Hui Wang + +commit c569242cd49287d53b73a94233db40097d838535 upstream. + +We have a BT headset (Lenovo Thinkplus XT99), the pairing and +connecting has no problem, once this headset is paired, bluez will +remember this device and will auto re-connect it whenever the device +is powered on. The auto re-connecting works well with Windows and +Android, but with Linux, it always fails. Through debugging, we found +at the rfcomm connection stage, the bluetooth stack reports +"Connection refused - security block (0x0003)". + +For this device, the re-connecting negotiation process is different +from other BT headsets, it sends the Link_KEY_REQUEST command before +the CONNECT_REQUEST completes, and it doesn't send ENCRYPT_CHANGE +command during the negotiation. When the device sends the "connect +complete" to hci, the ev->encr_mode is 1. + +So here in the conn_complete_evt(), if ev->encr_mode is 1, link type +is ACL and HCI_CONN_ENCRYPT is not set, we set HCI_CONN_ENCRYPT to +this conn, and update conn->enc_key_size accordingly. + +After this change, this BT headset could re-connect with Linux +successfully. This is the btmon log after applying the patch, after +receiving the "Connect Complete" with "Encryption: Enabled", will send +the command to read encryption key size: +> HCI Event: Connect Request (0x04) plen 10 + Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA) + Class: 0x240404 + Major class: Audio/Video (headset, speaker, stereo, video, vcr) + Minor class: Wearable Headset Device + Rendering (Printing, Speaker) + Audio (Speaker, Microphone, Headset) + Link type: ACL (0x01) +... +> HCI Event: Link Key Request (0x17) plen 6 + Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA) +< HCI Command: Link Key Request Reply (0x01|0x000b) plen 22 + Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA) + Link key: ${32-hex-digits-key} +... +> HCI Event: Connect Complete (0x03) plen 11 + Status: Success (0x00) + Handle: 256 + Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA) + Link type: ACL (0x01) + Encryption: Enabled (0x01) +< HCI Command: Read Encryption Key... (0x05|0x0008) plen 2 + Handle: 256 +< ACL Data TX: Handle 256 flags 0x00 dlen 10 + L2CAP: Information Request (0x0a) ident 1 len 2 + Type: Extended features supported (0x0002) +> HCI Event: Command Complete (0x0e) plen 7 + Read Encryption Key Size (0x05|0x0008) ncmd 1 + Status: Success (0x00) + Handle: 256 + Key size: 16 + +Cc: stable@vger.kernel.org +Link: https://github.com/bluez/bluez/issues/704 +Reviewed-by: Paul Menzel +Reviewed-by: Luiz Augusto von Dentz +Signed-off-by: Hui Wang +Signed-off-by: Luiz Augusto von Dentz +Signed-off-by: Greg Kroah-Hartman +--- + net/bluetooth/hci_event.c | 25 +++++++++++++++++++++++++ + 1 file changed, 25 insertions(+) + +--- a/net/bluetooth/hci_event.c ++++ b/net/bluetooth/hci_event.c +@@ -2453,6 +2453,31 @@ static void hci_conn_complete_evt(struct + if (test_bit(HCI_ENCRYPT, &hdev->flags)) + set_bit(HCI_CONN_ENCRYPT, &conn->flags); + ++ /* "Link key request" completed ahead of "connect request" completes */ ++ if (ev->encr_mode == 1 && !test_bit(HCI_CONN_ENCRYPT, &conn->flags) && ++ ev->link_type == ACL_LINK) { ++ struct link_key *key; ++ struct hci_cp_read_enc_key_size cp; ++ ++ key = hci_find_link_key(hdev, &ev->bdaddr); ++ if (key) { ++ set_bit(HCI_CONN_ENCRYPT, &conn->flags); ++ ++ if (!(hdev->commands[20] & 0x10)) { ++ conn->enc_key_size = HCI_LINK_KEY_SIZE; ++ } else { ++ cp.handle = cpu_to_le16(conn->handle); ++ if (hci_send_cmd(hdev, HCI_OP_READ_ENC_KEY_SIZE, ++ sizeof(cp), &cp)) { ++ bt_dev_err(hdev, "sending read key size failed"); ++ conn->enc_key_size = HCI_LINK_KEY_SIZE; ++ } ++ } ++ ++ hci_encrypt_cfm(conn, ev->status); ++ } ++ } ++ + /* Get remote features */ + if (conn->type == ACL_LINK) { + struct hci_cp_read_remote_features cp; diff --git a/queue-4.19/net-rds-fix-possible-cp-null-dereference.patch b/queue-4.19/net-rds-fix-possible-cp-null-dereference.patch new file mode 100644 index 00000000000..7d31f048808 --- /dev/null +++ b/queue-4.19/net-rds-fix-possible-cp-null-dereference.patch @@ -0,0 +1,66 @@ +From 62fc3357e079a07a22465b9b6ef71bb6ea75ee4b Mon Sep 17 00:00:00 2001 +From: Mahmoud Adam +Date: Tue, 26 Mar 2024 16:31:33 +0100 +Subject: net/rds: fix possible cp null dereference + +From: Mahmoud Adam + +commit 62fc3357e079a07a22465b9b6ef71bb6ea75ee4b upstream. + +cp might be null, calling cp->cp_conn would produce null dereference + +[Simon Horman adds:] + +Analysis: + +* cp is a parameter of __rds_rdma_map and is not reassigned. + +* The following call-sites pass a NULL cp argument to __rds_rdma_map() + + - rds_get_mr() + - rds_get_mr_for_dest + +* Prior to the code above, the following assumes that cp may be NULL + (which is indicative, but could itself be unnecessary) + + trans_private = rs->rs_transport->get_mr( + sg, nents, rs, &mr->r_key, cp ? cp->cp_conn : NULL, + args->vec.addr, args->vec.bytes, + need_odp ? ODP_ZEROBASED : ODP_NOT_NEEDED); + +* The code modified by this patch is guarded by IS_ERR(trans_private), + where trans_private is assigned as per the previous point in this analysis. + + The only implementation of get_mr that I could locate is rds_ib_get_mr() + which can return an ERR_PTR if the conn (4th) argument is NULL. + +* ret is set to PTR_ERR(trans_private). + rds_ib_get_mr can return ERR_PTR(-ENODEV) if the conn (4th) argument is NULL. + Thus ret may be -ENODEV in which case the code in question will execute. + +Conclusion: +* cp may be NULL at the point where this patch adds a check; + this patch does seem to address a possible bug + +Fixes: c055fc00c07b ("net/rds: fix WARNING in rds_conn_connect_if_down") +Cc: stable@vger.kernel.org # v4.19+ +Signed-off-by: Mahmoud Adam +Reviewed-by: Simon Horman +Link: https://lore.kernel.org/r/20240326153132.55580-1-mngyadam@amazon.com +Signed-off-by: Jakub Kicinski +Signed-off-by: Greg Kroah-Hartman +--- + net/rds/rdma.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/net/rds/rdma.c ++++ b/net/rds/rdma.c +@@ -279,7 +279,7 @@ static int __rds_rdma_map(struct rds_soc + kfree(sg); + ret = PTR_ERR(trans_private); + /* Trigger connection so that its ready for the next retry */ +- if (ret == -ENODEV) ++ if (ret == -ENODEV && cp) + rds_conn_connect_if_down(cp->cp_conn); + goto out; + } diff --git a/queue-4.19/netfilter-nf_tables-disallow-timeout-for-anonymous-sets.patch b/queue-4.19/netfilter-nf_tables-disallow-timeout-for-anonymous-sets.patch new file mode 100644 index 00000000000..7b01fee4b10 --- /dev/null +++ b/queue-4.19/netfilter-nf_tables-disallow-timeout-for-anonymous-sets.patch @@ -0,0 +1,43 @@ +From e26d3009efda338f19016df4175f354a9bd0a4ab Mon Sep 17 00:00:00 2001 +From: Pablo Neira Ayuso +Date: Fri, 16 Jun 2023 15:22:18 +0200 +Subject: netfilter: nf_tables: disallow timeout for anonymous sets + +From: Pablo Neira Ayuso + +commit e26d3009efda338f19016df4175f354a9bd0a4ab upstream. + +Never used from userspace, disallow these parameters. + +Signed-off-by: Pablo Neira Ayuso +[Keerthana: code surrounding the patch is different +because nft_set_desc is not present in v4.19-v5.10] +Signed-off-by: Keerthana K +Signed-off-by: Greg Kroah-Hartman +--- + net/netfilter/nf_tables_api.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +--- a/net/netfilter/nf_tables_api.c ++++ b/net/netfilter/nf_tables_api.c +@@ -3607,6 +3607,9 @@ static int nf_tables_newset(struct net * + if (!(flags & NFT_SET_TIMEOUT)) + return -EINVAL; + ++ if (flags & NFT_SET_ANONYMOUS) ++ return -EOPNOTSUPP; ++ + err = nf_msecs_to_jiffies64(nla[NFTA_SET_TIMEOUT], &timeout); + if (err) + return err; +@@ -3615,6 +3618,10 @@ static int nf_tables_newset(struct net * + if (nla[NFTA_SET_GC_INTERVAL] != NULL) { + if (!(flags & NFT_SET_TIMEOUT)) + return -EINVAL; ++ ++ if (flags & NFT_SET_ANONYMOUS) ++ return -EOPNOTSUPP; ++ + gc_int = ntohl(nla_get_be32(nla[NFTA_SET_GC_INTERVAL])); + } + diff --git a/queue-4.19/r8169-fix-issue-caused-by-buggy-bios-on-certain-boards-with-rtl8168d.patch b/queue-4.19/r8169-fix-issue-caused-by-buggy-bios-on-certain-boards-with-rtl8168d.patch new file mode 100644 index 00000000000..512b4fc794d --- /dev/null +++ b/queue-4.19/r8169-fix-issue-caused-by-buggy-bios-on-certain-boards-with-rtl8168d.patch @@ -0,0 +1,43 @@ +From 5d872c9f46bd2ea3524af3c2420a364a13667135 Mon Sep 17 00:00:00 2001 +From: Heiner Kallweit +Date: Sat, 30 Mar 2024 12:49:02 +0100 +Subject: r8169: fix issue caused by buggy BIOS on certain boards with RTL8168d + +From: Heiner Kallweit + +commit 5d872c9f46bd2ea3524af3c2420a364a13667135 upstream. + +On some boards with this chip version the BIOS is buggy and misses +to reset the PHY page selector. This results in the PHY ID read +accessing registers on a different page, returning a more or +less random value. Fix this by resetting the page selector first. + +Fixes: f1e911d5d0df ("r8169: add basic phylib support") +Cc: stable@vger.kernel.org +Signed-off-by: Heiner Kallweit +Reviewed-by: Simon Horman +Link: https://lore.kernel.org/r/64f2055e-98b8-45ec-8568-665e3d54d4e6@gmail.com +Signed-off-by: Jakub Kicinski +Signed-off-by: Greg Kroah-Hartman +--- + drivers/net/ethernet/realtek/r8169_main.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +--- a/drivers/net/ethernet/realtek/r8169_main.c ++++ b/drivers/net/ethernet/realtek/r8169_main.c +@@ -7303,6 +7303,15 @@ static int r8169_mdio_register(struct rt + struct mii_bus *new_bus; + int ret; + ++ /* On some boards with this chip version the BIOS is buggy and misses ++ * to reset the PHY page selector. This results in the PHY ID read ++ * accessing registers on a different page, returning a more or ++ * less random value. Fix this by resetting the page selector first. ++ */ ++ if (tp->mac_version == RTL_GIGA_MAC_VER_25 || ++ tp->mac_version == RTL_GIGA_MAC_VER_26) ++ r8169_mdio_write(tp, 0x1f, 0); ++ + new_bus = devm_mdiobus_alloc(&pdev->dev); + if (!new_bus) + return -ENOMEM; diff --git a/queue-4.19/series b/queue-4.19/series index ca4f70f1b62..0fc6bf8427c 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -117,3 +117,8 @@ scsi-libsas-stop-hardcoding-sas-address-length.patch scsi-libsas-introduce-struct-smp_disc_resp.patch scsi-libsas-add-a-helper-sas_get_sas_addr_and_dev_ty.patch scsi-libsas-fix-disk-not-being-scanned-in-after-bein.patch +r8169-fix-issue-caused-by-buggy-bios-on-certain-boards-with-rtl8168d.patch +bluetooth-hci_event-set-the-conn-encrypted-before-conn-establishes.patch +bluetooth-fix-toctou-in-hci-debugfs-implementation.patch +netfilter-nf_tables-disallow-timeout-for-anonymous-sets.patch +net-rds-fix-possible-cp-null-dereference.patch -- 2.47.3