Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3422302pxf; Mon, 29 Mar 2021 01:36:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYiM07q4KQeYZjGd8cOtNIABtLot7OFDPVMB+QK3b9ZpLzl3m7k3dqPyhhORX9L+dd16+1 X-Received: by 2002:a17:906:14d0:: with SMTP id y16mr27627709ejc.242.1617007001877; Mon, 29 Mar 2021 01:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007001; cv=none; d=google.com; s=arc-20160816; b=ZZD4PNywADpiga/oNFHFPM5Y+K63Ue6qz6/xtSE2CUY6RJmFkpgPaS6kB+Yxu1jE7C 7NVcF+FferSAJazqUJA/wpbAwZfdPaFkBq7Dr7EHU2hmSxLsFzpurwEKwt4xVSO857Qd XJDNUnGGtHAZzzzu+aeqgAL1dPN0W8iL6k1gXvDqkpiZMYxABaD/G0V9PAzUFBynjrX2 MfxUGaf4jH9bksbF5sGeCmHXkqLyRN7j33wRAIoudaNyKPT8nNBXwdW3mQ3dYWwPEfCo 8v/ALApEC948kFVfuwt5vKNzuPY+AF83v1HVb/m/vg1OBENoiaYwv2SkEB//ZfAJnNOs IsEA== 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=+kDfjuTE7OwBbOhqb0liHhOj/VpjaP3/xWr8t/Zjsls=; b=HEgWf8yWb0+zQOgG6LjCtQ8ewkTWMyLxCUqjTT5+gyAtB9f8e8v88kvpw/aOSZFU6j U4QGmd48M6B2zjuHRj1J97HnlsK+hV7pU3DbBgNy7KwDcCF5PXAuoStvlPef2ix9rzrS UOT/4wsuXYXwM3SGbyVn6B7EVhBWqIwYmrlMehcuQh/v+tIfaNagbCr1sopopo/aUJRh ILYnDSQgkbpHVw8djvJbYBMuGMeQ3Qc87F/q9U1oCcwRgkiIaAOfRwrPIVWIVVchBygy KEfghERd6gLrqZb56gBoyk32Qqc6YM/BgZEZuEoUxCQ6cIaY0c+ZVrRfnB8E8qYAswie XY6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=knV3oih+; 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 me5si13239126ejb.166.2021.03.29.01.36.19; Mon, 29 Mar 2021 01:36:41 -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=@linuxfoundation.org header.s=korg header.b=knV3oih+; 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 S234071AbhC2IcA (ORCPT + 99 others); Mon, 29 Mar 2021 04:32:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:36736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233493AbhC2IUG (ORCPT ); Mon, 29 Mar 2021 04:20:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADBBC61554; Mon, 29 Mar 2021 08:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006006; bh=jJeqaqIRW+9vGMbSvhZ/Ja9P9yQbphsEMcXoaK5bPUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knV3oih+I7R/n1NcETVt/W/VkftM9LKO4gPoz5XRSKDyd5i9kzaLdC/p4fEp0/i5m iGPDyrkAEdcD7Kd6dDILqaNqAB0yUK38gWuZZZbi1cRk+dOV+EoBSeKBIo3nXz+7wS HSoKRmarv2ECs87ibvQvIx8WMdZ7ayNGsUlrU3Bc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , Mimi Zohar Subject: [PATCH 5.10 083/221] integrity: double check iint_cache was initialized Date: Mon, 29 Mar 2021 09:56:54 +0200 Message-Id: <20210329075631.980796613@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@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: Mimi Zohar commit 92063f3ca73aab794bd5408d3361fd5b5ea33079 upstream. The kernel may be built with multiple LSMs, but only a subset may be enabled on the boot command line by specifying "lsm=". Not including "integrity" on the ordered LSM list may result in a NULL deref. As reported by Dmitry Vyukov: in qemu: qemu-system-x86_64 -enable-kvm -machine q35,nvdimm -cpu max,migratable=off -smp 4 -m 4G,slots=4,maxmem=16G -hda wheezy.img -kernel arch/x86/boot/bzImage -nographic -vga std -soundhw all -usb -usbdevice tablet -bt hci -bt device:keyboard -net user,host=10.0.2.10,hostfwd=tcp::10022-:22 -net nic,model=virtio-net-pci -object memory-backend-file,id=pmem1,share=off,mem-path=/dev/zero,size=64M -device nvdimm,id=nvdimm1,memdev=pmem1 -append "console=ttyS0 root=/dev/sda earlyprintk=serial rodata=n oops=panic panic_on_warn=1 panic=86400 lsm=smack numa=fake=2 nopcid dummy_hcd.num=8" -pidfile vm_pid -m 2G -cpu host But it crashes on NULL deref in integrity_inode_get during boot: Run /sbin/init as init process BUG: kernel NULL pointer dereference, address: 000000000000001c PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP KASAN CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.12.0-rc2+ #97 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-44-g88ab0c15525c-prebuilt.qemu.org 04/01/2014 RIP: 0010:kmem_cache_alloc+0x2b/0x370 mm/slub.c:2920 Code: 57 41 56 41 55 41 54 41 89 f4 55 48 89 fd 53 48 83 ec 10 44 8b 3d d9 1f 90 0b 65 48 8b 04 25 28 00 00 00 48 89 44 24 08 31 c0 <8b> 5f 1c 4cf RSP: 0000:ffffc9000032f9d8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff888017fc4f00 RCX: 0000000000000000 RDX: ffff888040220000 RSI: 0000000000000c40 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000000 R09: ffff888019263627 R10: ffffffff83937cd1 R11: 0000000000000000 R12: 0000000000000c40 R13: ffff888019263538 R14: 0000000000000000 R15: 0000000000ffffff FS: 0000000000000000(0000) GS:ffff88802d180000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000000000001c CR3: 000000000b48e000 CR4: 0000000000750ee0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: integrity_inode_get+0x47/0x260 security/integrity/iint.c:105 process_measurement+0x33d/0x17e0 security/integrity/ima/ima_main.c:237 ima_bprm_check+0xde/0x210 security/integrity/ima/ima_main.c:474 security_bprm_check+0x7d/0xa0 security/security.c:845 search_binary_handler fs/exec.c:1708 [inline] exec_binprm fs/exec.c:1761 [inline] bprm_execve fs/exec.c:1830 [inline] bprm_execve+0x764/0x19a0 fs/exec.c:1792 kernel_execve+0x370/0x460 fs/exec.c:1973 try_to_run_init_process+0x14/0x4e init/main.c:1366 kernel_init+0x11d/0x1b8 init/main.c:1477 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294 Modules linked in: CR2: 000000000000001c ---[ end trace 22d601a500de7d79 ]--- Since LSMs and IMA may be configured at build time, but not enabled at run time, panic the system if "integrity" was not initialized before use. Reported-by: Dmitry Vyukov Fixes: 79f7865d844c ("LSM: Introduce "lsm=" for boottime LSM selection") Cc: stable@vger.kernel.org Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/iint.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/security/integrity/iint.c +++ b/security/integrity/iint.c @@ -98,6 +98,14 @@ struct integrity_iint_cache *integrity_i struct rb_node *node, *parent = NULL; struct integrity_iint_cache *iint, *test_iint; + /* + * The integrity's "iint_cache" is initialized at security_init(), + * unless it is not included in the ordered list of LSMs enabled + * on the boot command line. + */ + if (!iint_cache) + panic("%s: lsm=integrity required.\n", __func__); + iint = integrity_iint_find(inode); if (iint) return iint;