[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240216152435.1575-8-petrtesarik@huaweicloud.com>
Date: Fri, 16 Feb 2024 16:24:34 +0100
From: Petr Tesarik <petrtesarik@...weicloud.com>
To: Dave Hansen <dave.hansen@...el.com>
Cc: Petr Tesařík <petr@...arici.cz>,
Petr Tesarik <petrtesarik@...weicloud.com>,
Jonathan Corbet <corbet@....net>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>,
Andy Lutomirski <luto@...nel.org>,
Oleg Nesterov <oleg@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Xin Li <xin3.li@...el.com>,
Arnd Bergmann <arnd@...db.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Rick Edgecombe <rick.p.edgecombe@...el.com>,
Kees Cook <keescook@...omium.org>,
"Masami Hiramatsu (Google)" <mhiramat@...nel.org>,
Pengfei Xu <pengfei.xu@...el.com>,
Josh Poimboeuf <jpoimboe@...nel.org>,
Ze Gao <zegao2021@...il.com>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Kai Huang <kai.huang@...el.com>,
David Woodhouse <dwmw@...zon.co.uk>,
Brian Gerst <brgerst@...il.com>,
Jason Gunthorpe <jgg@...pe.ca>,
Joerg Roedel <jroedel@...e.de>,
"Mike Rapoport (IBM)" <rppt@...nel.org>,
Tina Zhang <tina.zhang@...el.com>,
Jacob Pan <jacob.jun.pan@...ux.intel.com>,
"open list:DOCUMENTATION" <linux-doc@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>,
Roberto Sassu <roberto.sassu@...weicloud.com>,
David Howells <dhowells@...hat.com>,
Petr Tesarik <petr.tesarik1@...wei-partners.com>
Subject: [RFC 7/8] KEYS: Run PGP key parser in a sandbox
From: Roberto Sassu <roberto.sassu@...wei.com>
Test it with:
gpg --dearmor < <PGP key> | keyctl padd asymmetric "" @u
Signed-off-by: Roberto Sassu <roberto.sassu@...wei.com>
---
crypto/asymmetric_keys/pgp_public_key.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/crypto/asymmetric_keys/pgp_public_key.c b/crypto/asymmetric_keys/pgp_public_key.c
index 0529c8ce2d43..876bb83abdd5 100644
--- a/crypto/asymmetric_keys/pgp_public_key.c
+++ b/crypto/asymmetric_keys/pgp_public_key.c
@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mpi.h>
+#include <linux/sbm.h>
#include <keys/asymmetric-subtype.h>
#include <keys/asymmetric-parser.h>
#include <crypto/hash.h>
@@ -310,6 +311,12 @@ static struct asymmetric_key_ids *pgp_key_generate_id(
return NULL;
}
+static SBM_DEFINE_FUNC(parse_key, const unsigned char *, data, size_t, datalen,
+ struct pgp_key_data_parse_context *, ctx)
+{
+ return pgp_parse_packets(data, datalen, &ctx->pgp);
+}
+
/*
* Attempt to parse the instantiation data blob for a key as a PGP packet
* message holding a key.
@@ -318,6 +325,7 @@ static int pgp_key_parse(struct key_preparsed_payload *prep)
{
struct pgp_key_data_parse_context *ctx;
struct public_key *pub = NULL;
+ struct sbm sbm;
int ret;
kenter("");
@@ -332,7 +340,16 @@ static int pgp_key_parse(struct key_preparsed_payload *prep)
(1 << PGP_PKT_USER_ID);
ctx->pgp.process_packet = pgp_process_public_key;
- ret = pgp_parse_packets(prep->data, prep->datalen, &ctx->pgp);
+ sbm_init(&sbm);
+ ret = sbm_call(&sbm, parse_key,
+ SBM_COPY_IN(&sbm, prep->data, prep->datalen),
+ prep->datalen, SBM_COPY_INOUT(&sbm, ctx, sizeof(*ctx)));
+ sbm_destroy(&sbm);
+
+ if (ret < 0)
+ goto error;
+
+ ret = sbm_error(&sbm);
if (ret < 0)
goto error;
--
2.34.1
Powered by blists - more mailing lists