From patchwork Mon Aug 8 23:08:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17033 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 42B1BC3272 for ; Mon, 8 Aug 2022 23:08:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0751A63333; Tue, 9 Aug 2022 01:08:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660000129; bh=VieJwiGRICkhDuun+18JfNtghQfNkU4dOuNkXashPhM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CnDXfk9OEt+GxgnfVFoSUYmoDFq7GEgYC54V1boVx+qAr1beIkYiCermJ+QpVq+MZ S8jaap4q1nF1JCLpqv3tlLW/47o7vFEgHvqkjq4I8NMT1bb6bynqMtG1wYtLWekBb0 q5hqCOyVum4I74Cdq9Up6BA4X+18bKfGDNfuXbswXdEPhNJfetjwfdHufJwYtcZzbk OlEyh0Y46QqunXCFPxuH4pPdJaVV7BgKCL1tH/6dVKDoeSrwXeYnAjA9yNmd1JrYCR UPL7XRTE0OBsiws/53TgaM48jfmgTuBNJ5VSOs++V0oNAVPNEe2RtE9ZrhnBZyd2w0 uKD7UMfg9b2tQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD9C06332E for ; Tue, 9 Aug 2022 01:08:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TfV9WuSz"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5846F56D; Tue, 9 Aug 2022 01:08:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660000126; bh=VieJwiGRICkhDuun+18JfNtghQfNkU4dOuNkXashPhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TfV9WuSzfhUTJyMEO8RYA7JB5F3S1fOOMQXSMVkcV64kye/us42Fj8Bi6j00CKdKA dJN9zz/K+16/SF/1itT+hl8t2vqmfSoQl8R80YnJVDXiaL3zXDbQ1FKsBRaJllwYoE hgyt1B+UuPdWhmBlE4GJCzz+xCL/hm7/pk0qjk+0= To: libcamera-devel@lists.libcamera.org Date: Tue, 9 Aug 2022 02:08:31 +0300 Message-Id: <20220808230833.16275-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808230833.16275-1-laurent.pinchart@ideasonboard.com> References: <20220808230833.16275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] libcamera: pub_key: Gracefully handle failures to load public key 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-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" If the public key fails to load, PubKey::isValid() function returns false. The only user of the PubKey class, the IPAManager class, doesn't check that condition, and still calls the PubKey::verify() function, which leads to a crash. Fix this by returning false from PubKey::verify() if the key isn't valid, and log a warning in the IPAManager constructor to report the issue. Signed-off-by: Laurent Pinchart Reviewed-by: Eric Curtin Reviewed-by: Kieran Bingham --- src/libcamera/ipa_manager.cpp | 3 +++ src/libcamera/pub_key.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp index ec9660456960..2f96a2072fd6 100644 --- a/src/libcamera/ipa_manager.cpp +++ b/src/libcamera/ipa_manager.cpp @@ -109,6 +109,9 @@ IPAManager::IPAManager() LOG(IPAManager, Fatal) << "Multiple IPAManager objects are not allowed"; + if (!pubKey_.isValid()) + LOG(IPAManager, Warning) << "Public key not valid"; + unsigned int ipaCount = 0; /* User-specified paths take precedence. */ diff --git a/src/libcamera/pub_key.cpp b/src/libcamera/pub_key.cpp index 9bb08fda34af..b2045a103bc0 100644 --- a/src/libcamera/pub_key.cpp +++ b/src/libcamera/pub_key.cpp @@ -76,6 +76,9 @@ PubKey::~PubKey() bool PubKey::verify([[maybe_unused]] Span data, [[maybe_unused]] Span sig) const { + if (!valid_) + return false; + #if HAVE_GNUTLS const gnutls_datum_t gnuTlsData{ const_cast(data.data()),