Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3729318pxb; Mon, 24 Jan 2022 16:31:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBzL0TMSxl+UMggeNr/ChrQ+8NbgrICCw7GsPx8Kd8iQHcV/DLgB8i1/3Mfkw9VYt+Vx82 X-Received: by 2002:a17:902:704c:b0:14a:fd51:3b5d with SMTP id h12-20020a170902704c00b0014afd513b5dmr16006879plt.172.1643070719667; Mon, 24 Jan 2022 16:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643070719; cv=none; d=google.com; s=arc-20160816; b=O4HvxA1Ayq2/mBWdzVrkiSSSA95BYT0ZYAMoYg2WJW5UAHIebs/8zmgkvjsQSC+y7x +zh1rCoS3mp2ytSTv1HcNclSKj2wHPx0wEpX2gAcBtfL/jGsbUxrTER28p8yvcnWLB5g w8Yx4gZefZzZG01W2ygU2w0w4JPOGfCQEIu5XFNfAiuJ0/RA3qlaVDXOGJ9+IgOpTtmB 2PTgXTEYGNl7GXXT4gdvmcm9i0V+OUOVrnJE/HEurWncLNoqe/HYQiSJn44PkSeCSgls H5/AWezItRVUoFaXZnBHBwkSwCT5xfOVy2rBc84ipika+fqJ+UQ/VhD5+b/uccVFkqo3 F9BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TgafHb7DhYGn1cTS2BVzmuw/fOFswaw5PTIcKCz9hgM=; b=xkDt2bWVUiy0r+cDGrd8K6bWwZqEjyM0ON5STMusRzRFFHU6IKwKhfbsDfKWoUP4yX iV1esl0SLnbgFFdMMQeKH4IyRLb1tf6HOhojAEv7/7PwofR/9gNrAr9uB1PDSKskve4g QjHFAtGajVo2WZixAKtGwGtb1UkIDKyF8fp3ZcjoPW0dysBS3/p4IZ+F3EJlYUIXQvHG CQy9gNbAr1/erQmjSTYQNpA/OF2Xj6UcpksFyxQirGvbattcWYh2QwxMIi/QEVePP2zB QgM9X0Vcf9LXg914b62yGMJJtopHcWINa8zQBV0j6RQPfuxVXWMrB+6TwxS9aWGoppIy I+gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hfyJ5ae5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o3si6010299plg.446.2022.01.24.16.31.47; Mon, 24 Jan 2022 16:31:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hfyJ5ae5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S3409930AbiAYA14 (ORCPT + 99 others); Mon, 24 Jan 2022 19:27:56 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47644 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1455421AbiAXVfY (ORCPT ); Mon, 24 Jan 2022 16:35:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D8F37B81188; Mon, 24 Jan 2022 21:35:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DBDDC340E4; Mon, 24 Jan 2022 21:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060121; bh=x1i3tJn8RukdvFNMi9ic1oCJIRWOznFLbUVdgmlY8RA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfyJ5ae5VbX5nmYkJzEt4apwe65A/v/Gk7UeQBkLW1LubKBWGkikWO+YN+TaLvRkd NJ5pnzmbtP7arID/7QX12VtdD309yJrA0cY24pBin+3lk1WhEeEE5gCrDUNbsC9Kpn h4rvWuQqjfRNBSloqg5ZwLh8UkXS8o9bFeo1e2NM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Borislav Petkov , Tony Luck Subject: [PATCH 5.16 0847/1039] x86/mce: Check regs before accessing it Date: Mon, 24 Jan 2022 19:43:56 +0100 Message-Id: <20220124184153.757647457@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov commit 1acd85feba81084fcef00b73fc1601e42b77c5d8 upstream. Commit in Fixes accesses pt_regs before checking whether it is NULL or not. Make sure the NULL pointer check happens first. Fixes: 0a5b288e85bb ("x86/mce: Prevent severity computation from being instrumented") Reported-by: Dan Carpenter Signed-off-by: Borislav Petkov Reviewed-by: Tony Luck Link: https://lore.kernel.org/r/20211217102029.GA29708@kili Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/mce/severity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -222,6 +222,9 @@ static bool is_copy_from_user(struct pt_ struct insn insn; int ret; + if (!regs) + return false; + if (copy_from_kernel_nofault(insn_buf, (void *)regs->ip, MAX_INSN_SIZE)) return false; @@ -283,7 +286,7 @@ static noinstr int error_context(struct switch (fixup_type) { case EX_TYPE_UACCESS: case EX_TYPE_COPY: - if (!regs || !copy_user) + if (!copy_user) return IN_KERNEL; m->kflags |= MCE_IN_KERNEL_COPYIN; fallthrough;