From nobody Sun Feb 8 18:20:12 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53B2818C02F for ; Wed, 13 Nov 2024 21:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731533300; cv=none; b=rNRFmozY27nVAPBjCJ6REX3I7O4y5Vqin7klpC1Y4Mg9LsCisj4ptcRHBAStUeNRqOqJfTCRpJ7G5dAwBwgEXjgvD3OjG/6NwguMBB3YgzjTlqIoHG2L2Ia1Rs8ajkImM4KrqLt8PBzhdp0PbLQvLvfg92FXj/qjeFzmtUPnXJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731533300; c=relaxed/simple; bh=rKhHAG+LvAXKqEHhSlBUI3rw27sV72XPt1hCRbQISuo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Y3n1GFo0jm2EPg3VxD3pfr7WzfMWcyyP7gcTvPTXJf5ywdQ2bKG4SvRM1D/HIUbEIy88VnDzlvp21Ab8MfzLbhQEb6yEpUqtJZMYaR1YNrwj686OESpdbgDIeTGvwns5l2D1sXlnlSaCQYWeuCDhwHcAGYQcfPo1cpwXW3Um+60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sigma-star.at; spf=pass smtp.mailfrom=sigma-star.at; dkim=pass (2048-bit key) header.d=sigma-star.at header.i=@sigma-star.at header.b=gwdBbD+g; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sigma-star.at Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sigma-star.at Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sigma-star.at header.i=@sigma-star.at header.b="gwdBbD+g" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43152b79d25so62015545e9.1 for ; Wed, 13 Nov 2024 13:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sigma-star.at; s=google; t=1731533294; x=1732138094; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QQ6xAbIC8Al8OcOI95+3pwvP6j9wIJ23QXfOfXWSupE=; b=gwdBbD+gMOJlgKY4stYurbeaVqgSW9rmuoGPSWiXjDn3oz/rIOpGtrACiY82gWXTjo Pd/YotrMvXQx2xueYlulDGe6v/00u8vffQJj4xvSw0/JlMXxRcg2dngCdpiaQWeNNyuJ G3m0hP2HDFZpL0IL4JG+ypHPODSEofGffv4MejhEjGnOcLhH/bbmn8kRbbdSb7QsGIDb ksj/TwDceE7hjKTwxi1XMXMfEpdpyuDsHVbDoOcY6ZmKNVxZlXiDEQ6gtpNQdtODhhio HunON0sXyr1mIioyT489OrmOjIgiLWL/fnsPaZuDeIxRqpQT0+N/mD0Wqu+oxASUUjz5 znCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731533294; x=1732138094; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QQ6xAbIC8Al8OcOI95+3pwvP6j9wIJ23QXfOfXWSupE=; b=N524ca3ZsQtv/v0Z5zyVuEDFfG0JI44XFz09YV3QSg17Xs+Em3IvoF1Gr56HXgKYk9 CVRj4r5mZDgpR9eTEtaqAg/nQQPyruOz0mwe3WErOMEziA9XSFL7LTToh4hNMEZ/zCrh 3YKh9ocIM2rB9ZqpFE7av1MYjBmhhCE6taTh+8VTTP5rAughGELDIHNr/OCxQSQAngDS KzDSdvBlx7db9PYoFx7rcwDJjjo6oPI2WY+8f1+G7GiXhYTP19IKCu65fMz47EVZCSJ7 mS9MLB/QFFznSsiZ9Bv1RXfc29b8AtrUTaQR7PBn4ZZZXOJaYGPtccRruN56W5h7j/il xuXQ== X-Forwarded-Encrypted: i=1; AJvYcCWqEr+QmFgKUO+WiByXyq1bDPBkMAP7ueuCpyrg8p9jA/W1PjMupTL672J33+xfUdtH9x9TXo/etXQWcfM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzpn08L47qG01GDHvimnatRBSx6ReDn2HQn8is8hYIw9rbKL9xj zfH0Rgtrd22MKcxvWe5oJETNO6zgkjRtu6YkNKWbvOxhNOuh6+s7dzbrB6ssfdU= X-Google-Smtp-Source: AGHT+IEG3+0loCICljuOQmwpXB+TVjExLPGwnEULJ4Fhnr8A6GRVCEaGZc+hzlpvGDhdAwfNGhjx+w== X-Received: by 2002:a05:600c:b95:b0:431:57d2:d7b4 with SMTP id 5b1f17b1804b1-432d4ad3329mr37270825e9.26.1731533294505; Wed, 13 Nov 2024 13:28:14 -0800 (PST) Received: from localhost (17-14-180.cgnat.fonira.net. [185.17.14.180]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-432da265c45sm229285e9.11.2024.11.13.13.28.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Nov 2024 13:28:14 -0800 (PST) From: David Gstir To: sigma star Kernel Team , James Bottomley , Jarkko Sakkinen , Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, David Gstir , stable@vger.kernel.org Subject: [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y Date: Wed, 13 Nov 2024 22:27:54 +0100 Message-ID: <20241113212754.12758-1-david@sigma-star.at> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With vmalloc stack addresses enabled (CONFIG_VMAP_STACK=3Dy) DCP trusted keys can crash during en- and decryption of the blob encryption key via the DCP crypto driver. This is caused by improperly using sg_init_one() with vmalloc'd stack buffers (plain_key_blob). Fix this by always using kmalloc() for buffers we give to the DCP crypto driver. Cc: stable@vger.kernel.org # v6.10+ Fixes: 0e28bf61a5f9 ("KEYS: trusted: dcp: fix leak of blob encryption key") Signed-off-by: David Gstir --- security/keys/trusted-keys/trusted_dcp.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/security/keys/trusted-keys/trusted_dcp.c b/security/keys/trust= ed-keys/trusted_dcp.c index e908c53a803c..7b6eb655df0c 100644 --- a/security/keys/trusted-keys/trusted_dcp.c +++ b/security/keys/trusted-keys/trusted_dcp.c @@ -201,12 +201,16 @@ static int trusted_dcp_seal(struct trusted_key_payloa= d *p, char *datablob) { struct dcp_blob_fmt *b =3D (struct dcp_blob_fmt *)p->blob; int blen, ret; - u8 plain_blob_key[AES_KEYSIZE_128]; + u8 *plain_blob_key; =20 blen =3D calc_blob_len(p->key_len); if (blen > MAX_BLOB_SIZE) return -E2BIG; =20 + plain_blob_key =3D kmalloc(AES_KEYSIZE_128, GFP_KERNEL); + if (!plain_blob_key) + return -ENOMEM; + b->fmt_version =3D DCP_BLOB_VERSION; get_random_bytes(b->nonce, AES_KEYSIZE_128); get_random_bytes(plain_blob_key, AES_KEYSIZE_128); @@ -229,7 +233,8 @@ static int trusted_dcp_seal(struct trusted_key_payload = *p, char *datablob) ret =3D 0; =20 out: - memzero_explicit(plain_blob_key, sizeof(plain_blob_key)); + memzero_explicit(plain_blob_key, AES_KEYSIZE_128); + kfree(plain_blob_key); =20 return ret; } @@ -238,7 +243,7 @@ static int trusted_dcp_unseal(struct trusted_key_payloa= d *p, char *datablob) { struct dcp_blob_fmt *b =3D (struct dcp_blob_fmt *)p->blob; int blen, ret; - u8 plain_blob_key[AES_KEYSIZE_128]; + u8 *plain_blob_key =3D NULL; =20 if (b->fmt_version !=3D DCP_BLOB_VERSION) { pr_err("DCP blob has bad version: %i, expected %i\n", @@ -256,6 +261,12 @@ static int trusted_dcp_unseal(struct trusted_key_paylo= ad *p, char *datablob) goto out; } =20 + plain_blob_key =3D kmalloc(AES_KEYSIZE_128, GFP_KERNEL); + if (!plain_blob_key) { + ret =3D -ENOMEM; + goto out; + } + ret =3D decrypt_blob_key(b->blob_key, plain_blob_key); if (ret) { pr_err("Unable to decrypt blob key: %i\n", ret); @@ -271,7 +282,10 @@ static int trusted_dcp_unseal(struct trusted_key_paylo= ad *p, char *datablob) =20 ret =3D 0; out: - memzero_explicit(plain_blob_key, sizeof(plain_blob_key)); + if (plain_blob_key) { + memzero_explicit(plain_blob_key, AES_KEYSIZE_128); + kfree(plain_blob_key); + } =20 return ret; } --=20 2.47.0