Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp992713ybt; Fri, 19 Jun 2020 20:52:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdtUQ1q5ReTy8Lzra7nHL8vNAUwRZjR43ucdQeDIznQuYolssKkovUjriOcKjziRLQILQj X-Received: by 2002:aa7:d9d3:: with SMTP id v19mr6239512eds.364.1592625179285; Fri, 19 Jun 2020 20:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592625179; cv=none; d=google.com; s=arc-20160816; b=CI0prbsSTENxAE43CRrBFOIrfsXc6EQhwtnO7tJWx0DwE7p1vFoeblsFA5kmLVdole gaeCPiKDdf4UmfYOdCsfY/8jIpMzijSDolA/SbB3TezapQ4HJqzN8nCD991euzJvL+P7 iCNndQoNrjtHtJ0ormqp9Yxfm/2WcCKU/B5QUQYE39OI4T8aINStBsvOZw4QYHa+amYA LtCEON0I1RZIzIzd233Z/2MA9QdVnIFcUruMdTn/ma2XTiBoScsEKIpODlNfY6lshyeg dpnasvKmwFpWQn9CzdTbzJCgjKfF83ZK39QsiFdobyP5G8yvsrx9u5iXt+c7aTjL+yI/ Qpog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lUh3xkcCH9PxVkR+mN9ty7IunkelRk/iRX6xOxZ9zBA=; b=WwIGtN5anPH4yqcd3oy5t39GzSz65dJrLfImMrPLEparbTH6PXaaxuLa3acL84Z8SE D3hRxAUVcs8WT7DR8dCZn3dKl6naHNLBBmkUcoKZqcOLnETJcquPZJO7nHCM7TtzDkR4 9W8rj830IX404agb5UuNuoyXx4/Smk0woB0XuFM93lg2KJdNSbHDV3sSKcGj7ZVc91VR eFl1nF3TFpUeSfsfdt/bMtsy12Lb0pLh0XW0hMiQhekVSFKG2/qC/NV27BEkJC2ByA7N rCvWd9/1cY5GWiVTL/Qsf4YCecPYA/fQdmyb467Nn2j80rhCuwhz7/udUzBxKUaFWbeH lIPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WrS+LSY+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf16si5012528ejb.490.2020.06.19.20.52.37; Fri, 19 Jun 2020 20:52:59 -0700 (PDT) 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=@kernel.org header.s=default header.b=WrS+LSY+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394642AbgFSQUc (ORCPT + 99 others); Fri, 19 Jun 2020 12:20:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390410AbgFSPBY (ORCPT ); Fri, 19 Jun 2020 11:01:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 12A3720776; Fri, 19 Jun 2020 15:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578884; bh=AWo+FzPtuscLoyhgxZsRwU07bUkaec074OF380jB8Z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WrS+LSY+I5YdsRWXaiZOK+NfktKr2omYsFrmHPiC6tywGfIUrzbCrENqQN2VdI4qV VZfhwAMmK14zkdNlW4hjObErXi2AcOSVpVtH1XTi58yP6sx0zT4HV/uH1c8JmULIRB FkZeeX5oLg3usO/rav0clcizFRrR6Sc8B3QQc2Mw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Roberto Sassu , Mimi Zohar Subject: [PATCH 4.19 194/267] ima: Directly assign the ima_default_policy pointer to ima_rules Date: Fri, 19 Jun 2020 16:32:59 +0200 Message-Id: <20200619141658.058225592@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roberto Sassu commit 067a436b1b0aafa593344fddd711a755a58afb3b upstream. This patch prevents the following oops: [ 10.771813] BUG: kernel NULL pointer dereference, address: 0000000000000 [...] [ 10.779790] RIP: 0010:ima_match_policy+0xf7/0xb80 [...] [ 10.798576] Call Trace: [ 10.798993] ? ima_lsm_policy_change+0x2b0/0x2b0 [ 10.799753] ? inode_init_owner+0x1a0/0x1a0 [ 10.800484] ? _raw_spin_lock+0x7a/0xd0 [ 10.801592] ima_must_appraise.part.0+0xb6/0xf0 [ 10.802313] ? ima_fix_xattr.isra.0+0xd0/0xd0 [ 10.803167] ima_must_appraise+0x4f/0x70 [ 10.804004] ima_post_path_mknod+0x2e/0x80 [ 10.804800] do_mknodat+0x396/0x3c0 It occurs when there is a failure during IMA initialization, and ima_init_policy() is not called. IMA hooks still call ima_match_policy() but ima_rules is NULL. This patch prevents the crash by directly assigning the ima_default_policy pointer to ima_rules when ima_rules is defined. This wouldn't alter the existing behavior, as ima_rules is always set at the end of ima_init_policy(). Cc: stable@vger.kernel.org # 3.7.x Fixes: 07f6a79415d7d ("ima: add appraise action keywords and default rules") Reported-by: Takashi Iwai Signed-off-by: Roberto Sassu Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/ima/ima_policy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -196,7 +196,7 @@ static struct ima_rule_entry secure_boot static LIST_HEAD(ima_default_rules); static LIST_HEAD(ima_policy_rules); static LIST_HEAD(ima_temp_rules); -static struct list_head *ima_rules; +static struct list_head *ima_rules = &ima_default_rules; static int ima_policy __initdata; @@ -544,7 +544,6 @@ void __init ima_init_policy(void) temp_ima_appraise |= IMA_APPRAISE_POLICY; } - ima_rules = &ima_default_rules; ima_update_policy_flag(); }