Received: by 10.223.176.46 with SMTP id f43csp1571011wra; Wed, 24 Jan 2018 19:40:44 -0800 (PST) X-Google-Smtp-Source: AH8x224NgFVrrgSQg9AoL9xwWkamH8Fg/pibaoUIpjYWUyP0/d4JL5Uut4dsTOBE4xwnZt9LkRv7 X-Received: by 10.98.47.193 with SMTP id v184mr14586344pfv.90.1516851644355; Wed, 24 Jan 2018 19:40:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516851644; cv=none; d=google.com; s=arc-20160816; b=sJ9ZNyc8VsERltrp7jDg/khxZL5lG5n2OkJQ/bd895wPmCOlGuOR9SrI4C3rfw0Ld2 qYB89ZSXBndoaiaAgIQMidPSNkKE5aBxABAIR7wDmrSxcEcDIxdlJgi6kZcA9UMCVQl7 8LApQqKsBSgzCQEA/dDHvT7DwNW3FxnCXSiS/NQkMtRY9lpHQ0mId9JkJ81yTyF7I9Cg WzR8vDj3tVd+dTWfVnJ2Aq+GOBMT2DrSLgpHz9FgovFVauYVB2MXOvg7NXRm6CduTSBM I5GvyzEEdnCF80rA41HUbfYlk3vRVK4cBXZ+GmFQqMUM6lzLAdGZ79m1QnxZK8JNNuNF DKIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=qWo7Gz1d6/+C7B3Pt5Dv2QZ3MPpALCLFhn2HnIVRzcs=; b=L9uYaGNGLO8ANwYFru/yG9Qr1maZ8gkfVJAZJ/lW5jUPs+O4LCBwmpdEgGkIumx/gf yHWRPg4p0i5z9xtwsMUEi36Bg1Xx7O6DSDv/WJtRzJITGSXVyAvjlasKhTr3i0pBB4dm Uvrs+9CtDhX20vBicBFkMkz6xO40xZLU46VRxzj0KLh+txxHZN1U6dVEtXdRZPMnoBmb SptcpHNy2YZZoSXKQwA4rmMAWWuADHM7Kc0HuBRVjiFmnW2GYGGmHZhJMZut1zZowfeR R/y7Dj04OPmAMfUKG5Au7E3w69B4LHvGnsP48F/4E2ujjnCuN/VkkbQ5iTbr02WxCA+q NgDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=ddRKOa5G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10-v6si1222825plh.350.2018.01.24.19.40.30; Wed, 24 Jan 2018 19:40:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=ddRKOa5G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933485AbeAYDhc (ORCPT + 99 others); Wed, 24 Jan 2018 22:37:32 -0500 Received: from alln-iport-7.cisco.com ([173.37.142.94]:42730 "EHLO alln-iport-7.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932998AbeAYDhZ (ORCPT ); Wed, 24 Jan 2018 22:37:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=6958; q=dns/txt; s=iport; t=1516851445; x=1518061045; h=from:to:cc:subject:date:message-id; bh=aUfWEyM+KU+BNOEboSHkiKyZVkx9gWrq8iq+ZWXnVys=; b=ddRKOa5GQmpe0bzJxL8mkN2ovOuP8X8fE4ZF3LebkuBmK1wpkLUu8Nku C7NbInbjQdvSjKnyrPkAtyax91+GKicA5vqTXBGRvXD9avTCrkOvG0GyG VEq3VLVjNf0Qpw2agcbkxUlSTsmX+MdHVSvdMYpdOVORDmSjmQfVYvqzb 8=; X-IronPort-AV: E=Sophos;i="5.46,409,1511827200"; d="scan'208";a="60756962" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by alln-iport-7.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 03:27:57 +0000 Received: from sjc-ads-7132.cisco.com (sjc-ads-7132.cisco.com [10.30.217.207]) (authenticated bits=0) by rcdn-core-6.cisco.com (8.14.5/8.14.5) with ESMTP id w0P3Ruip007601 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Thu, 25 Jan 2018 03:27:56 GMT From: Taras Kondratiuk To: "H. Peter Anvin" , Al Viro , Arnd Bergmann , Rob Landley , Mimi Zohar , Jonathan Corbet , James McMechan Cc: initramfs@vger.kernel.org, Victor Kamensky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, xe-linux-external@cisco.com Subject: [PATCH v2 00/15] extend initramfs archive format to support xattrs Date: Thu, 25 Jan 2018 03:27:40 +0000 Message-Id: <1516850875-25066-1-git-send-email-takondra@cisco.com> X-Mailer: git-send-email 2.7.4 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Authenticated-User: takondra@cisco.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Many of the Linux security/integrity features are dependent on file metadata, stored as extended attributes (xattrs), for making decisions. These features need to be initialized during initcall and enabled as early as possible for complete security coverage. Initramfs (tmpfs) supports xattrs, but newc CPIO archive format does not support including them into the archive. There are several ways to include xattrs for initramfs: - Add TAR support. Complicated format and big headers looks like too much overhead. - Include a file manifest containing the xattrs in the CPIO. Should be easy for initramfs because we can set xattrs at the end when all files are extracted, but extracting such archive in userspace will be more complicated. For example it may be necessary to set SELinux labels for directories before extracting files into them, so manifest has to be extracted first and then searched during each file extraction. - Extend CPIO header to support xattrs. This seem to be the most straight forward way. It also allows to do other useful changes to CPIO format at the same time. E.g. increase filesize field to support files >4GB. This patch set extends the existing newc CPIO archive format to include xattrs in the initramfs. The series is based on v4.15-rc8. cpio_xattr branch is available here: https://github.com/kontar/linux/commits/cpio_xattr === Patch summary === Documentation: [PATCH 01/15] Documentation: add newcx initramfs format description Refactoring to simplify adding the new format: [PATCH 02/15] initramfs: replace states with function pointers [PATCH 03/15] initramfs: store file name in name_buf [PATCH 04/15] initramfs: remove unnecessary symlinks processing shortcut [PATCH 05/15] initramfs: move files creation into separate state [PATCH 06/15] initramfs: separate reading cpio method from header [PATCH 07/15] initramfs: split header layout information from parsing function Parse newxc format: [PATCH 08/15] initramfs: add newcx format [PATCH 09/15] initramfs: set extended attributes Generate newcx cpio archive: [PATCH 10/15] gen_init_cpio: move header formatting into function [PATCH 11/15] gen_init_cpio: add newcx format [PATCH 12/15] gen_init_cpio: set extended attributes for newcx [PATCH 13/15] gen_initramfs_list.sh: add -x option to enable newcx SELinux patches used for testing. They will be sent to SELinux maintainers separately. [PATCH 14/15] selinux: allow setxattr on rootfs so initramfs code can set them [PATCH 15/15] selinux: delay sid population for rootfs till init is complete === Testing === gen_initramfs_list.sh can be used to generate newcx CPIO archive: if CONFIG_INITRAMFS_NEWCX is enabled CONFIG_INITRAMFS_SOURCE will be packed into newcx archive. It is enough for basic testing, but it is not convenient for more complex setup. Victor have prepared a test setup with SELinux-labeled initramfs based on Poky(Yocto) with meta-selinux layer. Repo manifest and build instructions: https://github.com/victorkamensky/initramfs-xattrs-manifest Reference cpio utility patch to support newcx format could be found as part of poky/meta-selinux testing environment at https://raw.githubusercontent.com/victorkamensky/initramfs-xattrs-poky/rocko/meta/recipes-extended/cpio/cpio-2.12/cpio-xattrs.patch === History === The patch set is based on Mimi's series from Jan 2015: https://www.mail-archive.com/initramfs@vger.kernel.org/msg03971.html Latest discussion I was able to find is from Dec 2015: https://www.mail-archive.com/initramfs@vger.kernel.org/msg04198.html Format changes: - increased size of filesize to 64 bits to support files >4GB. - increased mtime field size to 64 bits to get usec precision and more than 32 bits of seconds. Rob mentioned nsec, but that will leave only 34 bits for seconds. If nsec precision is needed then we can add a separate 32 bit nsec field (it will match statx). - Checksum field is replased by xattrs_size field. Other fields are left unchanged. See patch format description in the patch #1. James suggested to add many other changes, but that will bloat header and make this new format very similar to tar. To keep format simple no other fields were added. v2 changes: - added documentation - made format more consistent. In previous version a sequence of fields in newcx header was different for symlinks and regular files (for symlinks data field was before xattrs). It was caused by a flow shortcut during symlink entry parsing. - removed unused checksum field in newcx header - removed redundant xattrcount at the beginning of xattr section (xattrs_size is enough to determine the end of section). - size of xattr entry in xattr section includes both name and value. This makes format more consistent and allows to jump over an entry without scanning for the end of name string first. - streamlined the state machine to address the previous issue and make it easier to add the new format - made header parsing data-driven to remove magic numbers and make it easier to add the new format - eliminated unnecessary buffer allocation for every file name - pass xattrs to gen_init_cpio via cpio_list file instead of reading them from files during packaging. This allows to set xattrs in CPIO even if they can't be set on a build machine. - incorporated several bug fixes from Victor Kamensky for v1 series Mimi Zohar (3): initramfs: separate reading cpio method from header initramfs: set extended attributes gen_initramfs_list.sh: add -x option to enable newcx format Taras Kondratiuk (10): Documentation: add newcx initramfs format description initramfs: replace states with function pointers initramfs: store file name in name_buf initramfs: remove unnecessary symlinks processing shortcut initramfs: move files creation into separate state initramfs: split header layout information from parsing function initramfs: add newcx format gen_init_cpio: move header formatting into function gen_init_cpio: add newcx format gen_init_cpio: set extended attributes for newcx format Victor Kamensky (2): selinux: allow setxattr on rootfs so initramfs code can set them selinux: delay sid population for rootfs till init is complete Documentation/early-userspace/buffer-format.txt | 46 ++- init/initramfs.c | 401 ++++++++++++++++++------ scripts/gen_initramfs_list.sh | 13 +- security/selinux/hooks.c | 19 ++ security/selinux/include/security.h | 1 + usr/Kconfig | 11 + usr/Makefile | 3 +- usr/gen_init_cpio.c | 364 ++++++++++++++------- 8 files changed, 626 insertions(+), 232 deletions(-) -- 2.10.3.dirty