Received: by 10.192.165.148 with SMTP id m20csp4140588imm; Mon, 30 Apr 2018 12:30:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoric3W17GqDrBBbzLK8khIVwSWuN/NvAb15JTjiFZjQdH0WT/eeC/osfbrO99VecHiFQwB X-Received: by 2002:a63:6f0c:: with SMTP id k12-v6mr11031892pgc.380.1525116613538; Mon, 30 Apr 2018 12:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525116613; cv=none; d=google.com; s=arc-20160816; b=bygj6+2jnWNKcBo6TVwrJElS+AnsBhkllPF84Qbl9W/2rsuTeSGgb93UBaWi11ZTe/ pJPDoG0dy2cDNuqJ45luOD5c3aygV8nZ5QVed7uI2t2ptLC7q5DT4vHB6ngAafG7t9Qu oQTbp+AHYbVGGwkWYu2we50HhPnYc4uxMHOJR0vrZR95bhMrbkvWidmIar+wAHclZknP eCXmivuX1Mu40nTzgXcAY535a7s+5UeGbDqpIaTZxlF+p11XwxDJBfenGCSLk1AIQISE iuFMnOlCHxu+yMR0d+TiEqME8YeAUEYzzY17ex7hshK4hYg4YSwjJphy78Iy0vp54UcP +TCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=Q1q9vkbGNj2f4zuwYEg+gzsgjFdEeT1CTGhqLoVha3g=; b=WKvDNjqBz/xlHBzGuiSfgy9aTcoQs2ykEPbcf6U5+shZ4E8MK8rup7fCWr+o9sXV4F oamKH16Ypmp1DLXYGWV9wm/K31XPJ2fIaqeHK8Vz+chFtvN5GTXuhpY84offSa+fXtiG RSE3DcQNDZlJ4uPskQbtOxG6s6knAfpHrBwptP2yaLqqt3hpXUDxggv+PtGu7cCKYsyJ lZN5cvfYn2LY8taCnGIZjHCybsDWa9LakZfz0softp0nNMZ9G4djBEPYmNBlR+ghZ180 LOrd2vxSev290X8jmd4ObbZnw/E2ggAnGVr9PKIBhaerKmonTsfSw6sHwya6jCoivGKE ZdMQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12-v6si6117911pgp.462.2018.04.30.12.29.29; Mon, 30 Apr 2018 12:30:13 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932503AbeD3T3G (ORCPT + 99 others); Mon, 30 Apr 2018 15:29:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:37460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932458AbeD3T3B (ORCPT ); Mon, 30 Apr 2018 15:29:01 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 03BF922DBF; Mon, 30 Apr 2018 19:29:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03BF922DBF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paulian Bogdan Marinca , Borislav Petkov , Tom Lendacky , Gary R Hook , Brijesh Singh , Herbert Xu Subject: [PATCH 4.16 112/113] crypto: ccp - add check to get PSP master only when PSP is detected Date: Mon, 30 Apr 2018 12:25:23 -0700 Message-Id: <20180430184019.919215109@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Brijesh Singh commit 716c7c32eae4b8a45c4f5602b50453865929b670 upstream. Paulian reported the below kernel crash on Ryzen 5 system: BUG: unable to handle kernel NULL pointer dereference at 0000000000000073 RIP: 0010:.LC0+0x41f/0xa00 RSP: 0018:ffffa9968003bdd0 EFLAGS: 00010002 RAX: ffffffffb113b130 RBX: 0000000000000000 RCX: 00000000000005a7 RDX: 00000000000000ff RSI: ffff8b46dee651a0 RDI: ffffffffb1bd617c RBP: 0000000000000246 R08: 00000000000251a0 R09: 0000000000000000 R10: ffffd81f11a38200 R11: ffff8b52e8e0a161 R12: ffffffffb19db220 R13: 0000000000000007 R14: ffffffffb17e4888 R15: 5dccd7affc30a31e FS: 0000000000000000(0000) GS:ffff8b46dee40000(0000) knlGS:0000000000000000 CR2: 0000000000000073 CR3: 000080128120a000 CR4: 00000000003406e0 Call Trace: ? sp_get_psp_master_device+0x56/0x80 ? map_properties+0x540/0x540 ? psp_pci_init+0x20/0xe0 ? map_properties+0x540/0x540 ? sp_mod_init+0x16/0x1a ? do_one_initcall+0x4b/0x190 ? kernel_init_freeable+0x19b/0x23c ? rest_init+0xb0/0xb0 ? kernel_init+0xa/0x100 ? ret_from_fork+0x22/0x40 Since Ryzen does not support PSP/SEV firmware hence i->psp_data will NULL in all sp instances. In those cases, 'i' will point to the list head after list_for_each_entry(). Dereferencing the head will cause kernel crash. Add check to call get master device only when PSP/SEV is detected. Reported-by: Paulian Bogdan Marinca Cc: Borislav Petkov Cc: Tom Lendacky CC: Gary R Hook Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccp/sp-dev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/crypto/ccp/sp-dev.c +++ b/drivers/crypto/ccp/sp-dev.c @@ -252,12 +252,12 @@ struct sp_device *sp_get_psp_master_devi goto unlock; list_for_each_entry(i, &sp_units, entry) { - if (i->psp_data) + if (i->psp_data && i->get_psp_master_device) { + ret = i->get_psp_master_device(); break; + } } - if (i->get_psp_master_device) - ret = i->get_psp_master_device(); unlock: write_unlock_irqrestore(&sp_unit_lock, flags); return ret;