From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751428AbdJ2W0Q (ORCPT ); Sun, 29 Oct 2017 18:26:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43620 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751152AbdJ2W0N (ORCPT ); Sun, 29 Oct 2017 18:26:13 -0400 Subject: Re: [PATCH 07/27] kexec_file: Disable at runtime if securelevel has been set From: Mimi Zohar To: joeyli Cc: David Howells , linux-security-module@vger.kernel.org, gnomes@lxorguk.ukuu.org.uk, linux-efi@vger.kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, jforbes@redhat.com, Matthew Garrett Date: Sun, 29 Oct 2017 18:26:05 -0400 In-Reply-To: <20171028083446.GG20348@linux-l9pv.suse> References: <150842463163.7923.11081723749106843698.stgit@warthog.procyon.org.uk> <150842468754.7923.10037578333644594134.stgit@warthog.procyon.org.uk> <1508774083.3639.124.camel@linux.vnet.ibm.com> <20171026074243.GM8550@linux-l9pv.suse> <1509027463.5886.26.camel@linux.vnet.ibm.com> <1509132746.3729.9.camel@linux.vnet.ibm.com> <20171028083446.GG20348@linux-l9pv.suse> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 17102922-0016-0000-0000-000004FB36B5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102922-0017-0000-0000-00002836B7FD Message-Id: <1509315965.3583.9.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-29_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710290320 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2017-10-28 at 16:34 +0800, joeyli wrote: > On Fri, Oct 27, 2017 at 03:32:26PM -0400, Mimi Zohar wrote: > > On Thu, 2017-10-26 at 10:17 -0400, Mimi Zohar wrote: > > > On Thu, 2017-10-26 at 15:42 +0800, joeyli wrote: > > > > Hi Mimi, > > > > > > > > Thank you for reviewing. > > > > > > > > On Mon, Oct 23, 2017 at 11:54:43AM -0400, Mimi Zohar wrote: > > > > > On Thu, 2017-10-19 at 15:51 +0100, David Howells wrote: > > > > > > From: Chun-Yi Lee > > > > > > > > > > > > When KEXEC_VERIFY_SIG is not enabled, kernel should not loads image > > > > > > through kexec_file systemcall if securelevel has been set. > > > > > > > > > > The patch title and description needs to be updated to refer to > > > > > lockdown, not securelevel. > > > > > > > > > > As previously mentioned the last time these patches were posted, this > > > > > leaves out testing to see if the integrity subsystem is enabled. > > > > > > > > > > Commit 503ceaef8e2e "ima: define a set of appraisal rules requiring > > > > > file signatures" was upstreamed.  An additional patch could force > > > > > these rules to be added to the custom policy, if lockdown is enabled. > > > > >  This and other patches in this series could then check to see if > > > > > is_ima_appraise_enabled() is true. > > > > > > > > > > Mimi > > > > > > > > > > > > > I have updated the patch title and description, and I also added > > > > is_ima_appraise_enabled() as the following. Is it good to you? > > > > > > Yes, that works.  Thanks!  Remember is_ima_appraise_enabled() is > > > dependent on the "ima: require secure_boot rules in lockdown mode" > > > patch - http://kernsec.org/pipermail/linux-security-module-archive/201 > > > 7-October/003910.html. > > > > > > The IMA "secure_boot" policy can be specified on the boot command line > > > as ima_policy="secure_boot".  It requires kernel modules, firmware, > > > kexec kernel image and the IMA custom policy to be signed.  In > > > lockdown mode, these rules are enabled by default and added to the > > > custom policy. > > > > > > > On the other hand, I am not good on IMA. I have traced the code path > > > > in kimage_file_prepare_segments(). Looks that the READING_KEXEC_IMAGE > > > > doesn't show in selinux_kernel_read_file(). Where is the exact code > > > > in IMA for checking the signature when loading crash kernel file? > > > > > > kernel_read_file_from_fd() calls the security_kernel_read_file() and > > > security_kernel_post_read_file() hooks, which call ima_read_file() and > > > ima_post_read_file() respectively. > > > > Hm, with "lockdown" enabled on the boot command line, I'm now able to > > do the kexec load, but not the unload. :/   After the kexec load with > > I have tried on Qemu with OVMF, I can load and unload second kernel by > kexec tool (on openSUSE is in kexec-tools RPM): > > # kexec -u -s Thanks, I left off the "-s" option, causing it to fail.  This is the correct behavior.  So both with/without the "-s" option are working properly. > I add -s for using kexec-load-file, and I signed kernel by pesign. > > > the "--reuse-cmdline" option, the system reboots, but isn't in > > "lockdown" mode. > > > > Either enabling secure boot in EFI firmware or using _lockdown_ kernel > parameter, the second kernel can be locked down on my OVMF VM. > > I used following commands: > > # kexec -s -l /boot/vmlinuz-4.14.0-rc2-default+ --append="$(cat /proc/cmdline)" --initrd=/boot/initrd-4.14.0-rc2-default+ > # umount -a; mount -o remount,ro /I' > # kexec -e > > The kernel source is from David's linux-fs git with lockdown-20171026 tag. > The kernel is also signed by pesign. Yes, based on the patches in David's tree, "lockdown" is being carried to the target OS properly. Mimi