From patchwork Wed Jan 12 23:41:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Ruffell X-Patchwork-Id: 1579399 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=uu9lnkxk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JZ3xD1XrVz9sP7 for ; Thu, 13 Jan 2022 10:41:35 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1n7nF9-0002vg-J4; Wed, 12 Jan 2022 23:41:27 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1n7nF7-0002vS-94 for kernel-team@lists.ubuntu.com; Wed, 12 Jan 2022 23:41:25 +0000 Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 206F23F17B for ; Wed, 12 Jan 2022 23:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642030885; bh=vt9Nwg+FijhO9fDZ1ihceRclmir4mrrl/gOw8YZsPqI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=uu9lnkxkJY9g/KZksGZiWwIQ+ktQryqRwJK6lZWgeSHXssNehuNKd9kexoq46G8Ev sHygkrCjeop3eWXqbqpezjletT34JfDIYD+RjIG8t4ztcMk/dRRBE/1RMSEP4+KKuc e8/Dd+wYv6rTSSen5ZbTYIkQzrzAZIySNga94OV/ZIZ8wXDzw771tic6wzamW0/j9m dw3wrMELH+EPBJMoVue7eVaWWIdigg6uZXlkWqTW9hV6/+5HCSP558jlm33pg1jNk6 zd64r/W3+laUZaivKX3VCHaW3uj0ojodhaVxV1GmA4M/7FIdX5ZzrFmT7zIhtVMEL+ JET7XLhEUaMfw== Received: by mail-il1-f198.google.com with SMTP id i9-20020a056e021b0900b002b799b36190so2703356ilv.13 for ; Wed, 12 Jan 2022 15:41:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vt9Nwg+FijhO9fDZ1ihceRclmir4mrrl/gOw8YZsPqI=; b=aALoSipb5t4eHe5wNHkW1RuKSOg2QLhm1/GBx0eL8i8tQMlamDcfMRcraOHawYId80 SsaTwmzaouv88ToSU2IFBXuFsGyFLNpdMmDWHp/4xHGEf9ImMRoeooKlNCCDEz40HIIK JCCaTPonCK4/dtJdExF0OOe+Hwri3WRflLyVfph0xjwmF4tect2g7bndPu16ke0GqpSj X5rmQf1nAvRjY7dLOaSxc7Hg9PK7Ahk0XiMFMwo2vMrdHPQamjTUKJztFi4z3TAdStYG kb1CIppc+FRbbp5vhPHrFmho1teIDKxl59oFmoUB4pFj/+GFTGbMv/Y/y4zyhd3CjBB6 7Z1g== X-Gm-Message-State: AOAM530TVBoXKtRl7DLe6t2eCGO0zSt2+EmxRyUfYfqCRxm0H7JqB5il r/V11SGUP3Ap9jaQQDAtkhmE+lV7xG8Xmu7aw+JZee3BiIUenxEIxWGxi0pUcxc4A0nzS4fVDT1 lnkHOPXIsIzoiwvX3+XYRkVceyfJA3suFvpjL8BAGkg== X-Received: by 2002:a05:6e02:1586:: with SMTP id m6mr1075739ilu.227.1642030883832; Wed, 12 Jan 2022 15:41:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFFmnvdAiiCgBhSepxQqIju+yAHA//6DzPCTRA6MRlco5Az9sC0/ddIbFnGJdVON8vDKpojg== X-Received: by 2002:a05:6e02:1586:: with SMTP id m6mr1075736ilu.227.1642030883462; Wed, 12 Jan 2022 15:41:23 -0800 (PST) Received: from desktop.. (122-62-52-82-fibre.sparkbb.co.nz. [122.62.52.82]) by smtp.gmail.com with ESMTPSA id c18sm798949iod.18.2022.01.12.15.41.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 15:41:23 -0800 (PST) From: Matthew Ruffell To: kernel-team@lists.ubuntu.com Subject: [SRU][Impish][PATCH 0/1] amd_sfh: Null pointer dereference on early device init causes early panic and fails to boot Date: Thu, 13 Jan 2022 12:41:14 +1300 Message-Id: <20220112234115.11152-1-matthew.ruffell@canonical.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1956519 [Impact] A regression was introduced into 5.13.0-23-generic for devices using AMD Ryzen chipsets that incorporate AMD Sensor Fusion Hub (SFH) HID devices, which are mostly Ryzen based laptops, but desktops do have the SOC embedded as well. On early boot, when the driver initialises the device, it hits a null pointer dereference with the following stack trace: BUG: kernel NULL pointer dereference, address: 000000000000000c #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 0 P4D 0 Oops: 0002 [#1] SMP NOPTI CPU: 0 PID: 175 Comm: systemd-udevd Not tainted 5.13.0-23-generic #23-Ubuntu RIP: 0010:amd_sfh_hid_client_init+0x47/0x350 [amd_sfh] Call Trace: ? __pci_set_master+0x5f/0xe0 amd_mp2_pci_probe+0xad/0x160 [amd_sfh] local_pci_probe+0x48/0x80 pci_device_probe+0x105/0x1c0 really_probe+0x24b/0x4c0 driver_probe_device+0xf0/0x160 device_driver_attach+0xab/0xb0 __driver_attach+0xb2/0x140 ? device_driver_attach+0xb0/0xb0 bus_for_each_dev+0x7e/0xc0 driver_attach+0x1e/0x20 bus_add_driver+0x135/0x1f0 driver_register+0x95/0xf0 ? 0xffffffffc03d2000 __pci_register_driver+0x57/0x60 amd_mp2_pci_driver_init+0x23/0x1000 [amd_sfh] do_one_initcall+0x48/0x1d0 ? kmem_cache_alloc_trace+0xfb/0x240 do_init_module+0x62/0x290 load_module+0xa8f/0xb10 __do_sys_finit_module+0xc2/0x120 __x64_sys_finit_module+0x18/0x20 do_syscall_64+0x61/0xb0 ? ksys_mmap_pgoff+0x135/0x260 ? exit_to_user_mode_prepare+0x37/0xb0 ? syscall_exit_to_user_mode+0x27/0x50 ? __x64_sys_mmap+0x33/0x40 ? do_syscall_64+0x6e/0xb0 ? do_syscall_64+0x6e/0xb0 ? do_syscall_64+0x6e/0xb0 ? syscall_exit_to_user_mode+0x27/0x50 ? do_syscall_64+0x6e/0xb0 ? exc_page_fault+0x8f/0x170 ? asm_exc_page_fault+0x8/0x30 entry_SYSCALL_64_after_hwframe+0x44/0xae This causes a panic and the system is unable to continue booting, and the user must select an older kernel to boot. [Fix] The issue was introduced in 5.13.0-23-generic by the commit: commit d46ef750ed58cbeeba2d9a55c99231c30a172764 commit-impish 56559d7910e704470ad72da58469b5588e8cbf85 Author: Evgeny Novikov Date: Tue Jun 1 19:38:01 2021 +0300 Subject:HID: amd_sfh: Fix potential NULL pointer dereference Link: https://github.com/torvalds/linux/commit/d46ef750ed58cbeeba2d9a55c99231c30a172764 The issue is pretty straightforward, amd_sfh_client.c attempts to dereference cl_data, but it is NULL: $ eu-addr2line -ifae ./usr/lib/debug/lib/modules/5.13.0-23-generic/kernel/drivers/hid/amd-sfh-hid/amd_sfh.ko amd_sfh_hid_client_init+0x47 0x0000000000000767 amd_sfh_hid_client_init /build/linux-k2e9CH/linux-5.13.0/drivers/hid/amd-sfh-hid/amd_sfh_client.c:147:27 134 int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) 135 { ... 146 147 cl_data->num_hid_devices = amd_mp2_get_sensor_num(privdata, &cl_data->sensor_idx[0]); 148 ... The patch moves the call to amd_sfh_hid_client_init() before privdata->cl_data is actually allocated by devm_kzalloc, hence cl_data being NULL. + rc = amd_sfh_hid_client_init(privdata); + if (rc) + return rc; + privdata->cl_data = devm_kzalloc(&pdev->dev, sizeof(struct amdtp_cl_data), GFP_KERNEL); if (!privdata->cl_data) return -ENOMEM; ... - return amd_sfh_hid_client_init(privdata); + return 0; The issue was fixed upstream in 5.15-rc4 by the commit: commit 88a04049c08cd62e698bc1b1af2d09574b9e0aee Author: Basavaraj Natikar Date: Thu Sep 23 17:59:27 2021 +0530 Subject: HID: amd_sfh: Fix potential NULL pointer dereference Link: https://github.com/torvalds/linux/commit/88a04049c08cd62e698bc1b1af2d09574b9e0aee The fix places the call to amd_sfh_hid_client_init() after privdata->cl_data is allocated, and it changes the order of amd_sfh_hid_client_init() to happen before devm_add_action_or_reset() fixing the actual null pointer dereference which caused these commits to exist. This patch also landed in 5.14.10 -stable, but it seems it was omitted from being backported to impish, likely due to it sharing the exact same subject line as the regression commit, so it was likely dropped as a duplicate? [Testcase] You need an AMD Ryzen based system that has a AMD Sensor Fusion Hub HID device built in to test this. Simply booting the system is enough to trigger the issue. A test kernel is available in the following ppa: https://launchpad.net/~mruffell/+archive/ubuntu/lp1956519-test A community user has tested the test kernel, and has confirmed that it fixes the issue. [Where problems could occur] If a regression were to occur, it would only affect AMD Ryzen based systems with the AMD Sensor Fusion Hub HID device SOC. Since the changes affect the device initialisation function, a regression could cause systems to panic during boot, forcing users to revert to older kernels to start their systems. Saying that, the patch is present in 5.15-rc4 and is in 5.14.10, and is in widespread use, and is already present in Jammy. Basavaraj Natikar (1): HID: amd_sfh: Fix potential NULL pointer dereference drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)