From patchwork Wed Apr 29 01:33:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3608 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 094C1603F4 for ; Wed, 29 Apr 2020 03:33:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NW8eyRXM"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 86CB1521 for ; Wed, 29 Apr 2020 03:33:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588124035; bh=6c7QNg9UEI5CZi3GiSqf6MUUmtQE7GhWVhhAfRDMsfQ=; h=From:To:Subject:Date:From; b=NW8eyRXMz40aNz+7vrxuAOAOCqodJ1M0xlvq1z8x9CLiBvzoqAoTyShaumZMIqYPA qG41CyQkuthOFtyW+BIEUVC+0ffZlY+qeFCAyVMVLiLq8ExLnU+6EfJ47bN9trnE4j VT0zjkItygZowlatvGZHgPjrLCGIIVnTGpEwYkT4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 29 Apr 2020 04:33:49 +0300 Message-Id: <20200429013349.2389-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: Regenerate IPA module signatures at install time X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2020 01:33:56 -0000 When the IPA modules are installed, meson strips the DT_RPATH and DT_RUNPATH from the binaries. This invalidates the signatures. Disable installation of the .sign files and add an installation script to regenerate them directly in the target directory. The .sign files still need to be created at build time to support running IPA modules from the build tree. Two alternative approaches have been considered: - meson could be taught a new target argument to preserve binary compatibility by skipping any operation that modifies files. This has been proposed in the #mesonbuild IRC channel. While this could be interesting in the longer term, we need to fix the issue now. - The module signatures could be computed on selected sections only. While skipping the .dynamic section when signing may not cause security issues, it would make signature generation and verification more complex, and wasn't deemed worth it. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/ipa-sign-install.sh | 18 ++++++++++++++++++ src/ipa/meson.build | 9 +++++++++ src/ipa/rkisp1/meson.build | 2 +- src/ipa/vimc/meson.build | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100755 src/ipa/ipa-sign-install.sh diff --git a/src/ipa/ipa-sign-install.sh b/src/ipa/ipa-sign-install.sh new file mode 100755 index 000000000000..5317a8a2042b --- /dev/null +++ b/src/ipa/ipa-sign-install.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2020, Google Inc. +# +# Author: Laurent Pinchart +# +# ipa-sign-install.sh - Regenerate IPA module signatures when installing + +libdir=$1 +key=$2 + +ipa_sign=$(dirname "$0")/ipa-sign.sh + +echo "Regenerating IPA modules signatures" + +for module in "${MESON_INSTALL_DESTDIR_PREFIX}/${libdir}"/*.so ; do + "${ipa_sign}" "${key}" "${module}" "${module}.sign" +done diff --git a/src/ipa/meson.build b/src/ipa/meson.build index 145bf8105af7..56e65eaa7426 100644 --- a/src/ipa/meson.build +++ b/src/ipa/meson.build @@ -25,3 +25,12 @@ foreach pipeline : get_option('pipelines') subdir(pipeline) endif endforeach + +if ipa_sign_module + # Regenerate the signatures for all IPA modules. We can't simply install the + # .sign files, as meson strips the DT_RPATH and DT_RUNPATH from binaries at + # install time, which invalidates the signatures. + meson.add_install_script('ipa-sign-install.sh', + ipa_install_dir, + ipa_priv_key.full_path()) +endif diff --git a/src/ipa/rkisp1/meson.build b/src/ipa/rkisp1/meson.build index 247d0429b49c..98dbbd632c12 100644 --- a/src/ipa/rkisp1/meson.build +++ b/src/ipa/rkisp1/meson.build @@ -14,6 +14,6 @@ if ipa_sign_module input : mod, output : ipa_name + '.so.sign', command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ], - install : true, + install : false, install_dir : ipa_install_dir) endif diff --git a/src/ipa/vimc/meson.build b/src/ipa/vimc/meson.build index f8650ee80461..9d0760e57cc1 100644 --- a/src/ipa/vimc/meson.build +++ b/src/ipa/vimc/meson.build @@ -14,7 +14,7 @@ if ipa_sign_module input : mod, output : ipa_name + '.so.sign', command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ], - install : true, + install : false, install_dir : ipa_install_dir) endif