From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9976C433DF for ; Fri, 19 Jun 2020 16:51:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9762820734 for ; Fri, 19 Jun 2020 16:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592585465; bh=YOkpTZYrfnokcdFwYS0WPntzIjGXEEp96uDBgKME3hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=o6UdEKfuD9+B1SNKs5fI/R4GsQCty5Wxul7u1lCygbx+pChVe+h+ppsunqumUHRMn WyayqgUBGFCzeWE0Nql54vT5DiIUJfwSaq755UeCWddkAEJZJQbMB5U3kmijAvGlkn X+CzD31NIz71eUT7s/7CsMfySeqte+ju0QpNUwGg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388079AbgFSQuu (ORCPT ); Fri, 19 Jun 2020 12:50:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:55676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387885AbgFSOid (ORCPT ); Fri, 19 Jun 2020 10:38:33 -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 D832D2070A; Fri, 19 Jun 2020 14:38:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577513; bh=YOkpTZYrfnokcdFwYS0WPntzIjGXEEp96uDBgKME3hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uUwoRSmgXzJ6E+AKBLuACjMANvuJUwXEps6x/pPLgzvAGF/a4AIbRRpq8uUKXcQg9 dtQuoZCKYbXUqa8Gdlw72e1Rl1nno32HKdWy3FeesvruV+Ofa4/X5XXlPVYNJskrTG v9p+ozG2VHB8xUEkJ1ezRM4hB3tXhsTBnCc5XJq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Roberto Sassu , Mimi Zohar , Sasha Levin Subject: [PATCH 4.4 081/101] ima: Directly assign the ima_default_policy pointer to ima_rules Date: Fri, 19 Jun 2020 16:33:10 +0200 Message-Id: <20200619141618.229547024@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141614.001544111@linuxfoundation.org> References: <20200619141614.001544111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Roberto Sassu [ Upstream commit 067a436b1b0aafa593344fddd711a755a58afb3b ] 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: Sasha Levin --- security/integrity/ima/ima_policy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 3997e206f82d..0ddc8cb6411b 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -135,7 +135,7 @@ static struct ima_rule_entry default_appraise_rules[] = { static LIST_HEAD(ima_default_rules); static LIST_HEAD(ima_policy_rules); -static struct list_head *ima_rules; +static struct list_head *ima_rules = &ima_default_rules; static DEFINE_MUTEX(ima_rules_mutex); @@ -412,7 +412,6 @@ void __init ima_init_policy(void) &ima_default_rules); } - ima_rules = &ima_default_rules; } /** -- 2.25.1