From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
syzbot+ec24e95ea483de0a24da@syzkaller.appspotmail.com,
Eric Biggers <ebiggers@google.com>,
David Howells <dhowells@redhat.com>,
James Morris <james.morris@microsoft.com>
Subject: [PATCH 4.14 57/71] KEYS: always initialize keyring_index_key::desc_len
Date: Mon, 25 Feb 2019 22:11:59 +0100 [thread overview]
Message-ID: <20190225195038.930280539@linuxfoundation.org> (raw)
In-Reply-To: <20190225195034.555044862@linuxfoundation.org>
4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <ebiggers@google.com>
commit ede0fa98a900e657d1fcd80b50920efc896c1a4c upstream.
syzbot hit the 'BUG_ON(index_key->desc_len == 0);' in __key_link_begin()
called from construct_alloc_key() during sys_request_key(), because the
length of the key description was never calculated.
The problem is that we rely on ->desc_len being initialized by
search_process_keyrings(), specifically by search_nested_keyrings().
But, if the process isn't subscribed to any keyrings that never happens.
Fix it by always initializing keyring_index_key::desc_len as soon as the
description is set, like we already do in some places.
The following program reproduces the BUG_ON() when it's run as root and
no session keyring has been installed. If it doesn't work, try removing
pam_keyinit.so from /etc/pam.d/login and rebooting.
#include <stdlib.h>
#include <unistd.h>
#include <keyutils.h>
int main(void)
{
int id = add_key("keyring", "syz", NULL, 0, KEY_SPEC_USER_KEYRING);
keyctl_setperm(id, KEY_OTH_WRITE);
setreuid(5000, 5000);
request_key("user", "desc", "", id);
}
Reported-by: syzbot+ec24e95ea483de0a24da@syzkaller.appspotmail.com
Fixes: b2a4df200d57 ("KEYS: Expand the capacity of a keyring")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: James Morris <james.morris@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
security/keys/keyring.c | 4 +---
security/keys/proc.c | 3 +--
security/keys/request_key.c | 1 +
security/keys/request_key_auth.c | 2 +-
4 files changed, 4 insertions(+), 6 deletions(-)
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -661,9 +661,6 @@ static bool search_nested_keyrings(struc
BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
(ctx->flags & STATE_CHECKS) == STATE_CHECKS);
- if (ctx->index_key.description)
- ctx->index_key.desc_len = strlen(ctx->index_key.description);
-
/* Check to see if this top-level keyring is what we are looking for
* and whether it is valid or not.
*/
@@ -921,6 +918,7 @@ key_ref_t keyring_search(key_ref_t keyri
struct keyring_search_context ctx = {
.index_key.type = type,
.index_key.description = description,
+ .index_key.desc_len = strlen(description),
.cred = current_cred(),
.match_data.cmp = key_default_cmp,
.match_data.raw_data = description,
--- a/security/keys/proc.c
+++ b/security/keys/proc.c
@@ -188,8 +188,7 @@ static int proc_keys_show(struct seq_fil
int rc;
struct keyring_search_context ctx = {
- .index_key.type = key->type,
- .index_key.description = key->description,
+ .index_key = key->index_key,
.cred = m->file->f_cred,
.match_data.cmp = lookup_user_key_possessed,
.match_data.raw_data = key,
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -545,6 +545,7 @@ struct key *request_key_and_link(struct
struct keyring_search_context ctx = {
.index_key.type = type,
.index_key.description = description,
+ .index_key.desc_len = strlen(description),
.cred = current_cred(),
.match_data.cmp = key_default_cmp,
.match_data.raw_data = description,
--- a/security/keys/request_key_auth.c
+++ b/security/keys/request_key_auth.c
@@ -246,7 +246,7 @@ struct key *key_get_instantiation_authke
struct key *authkey;
key_ref_t authkey_ref;
- sprintf(description, "%x", target_id);
+ ctx.index_key.desc_len = sprintf(description, "%x", target_id);
authkey_ref = search_process_keyrings(&ctx);
next prev parent reply other threads:[~2019-02-25 21:59 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-25 21:11 [PATCH 4.14 00/71] 4.14.104-stable review Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 01/71] ARM: 8834/1: Fix: kprobes: optimized kprobes illegal instruction Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 02/71] tracing: Fix number of entries in trace header Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 03/71] MIPS: eBPF: Always return sign extended 32b values Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 04/71] mac80211: Restore vif beacon interval if start ap fails Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 05/71] mac80211: Free mpath object when rhashtable insertion fails Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 06/71] libceph: handle an empty authorize reply Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 07/71] ceph: avoid repeatedly adding inode to mdsc->snap_flush_list Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 08/71] numa: change get_mempolicy() to use nr_node_ids instead of MAX_NUMNODES Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 09/71] proc, oom: do not report alien mms when setting oom_score_adj Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 10/71] KEYS: allow reaching the keys quotas exactly Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 11/71] mfd: ti_am335x_tscadc: Use PLATFORM_DEVID_AUTO while registering mfd cells Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 12/71] pvcalls-back: set -ENOTCONN in pvcalls_conn_back_read Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 13/71] mfd: twl-core: Fix section annotations on {,un}protect_pm_master Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 14/71] mfd: db8500-prcmu: Fix some section annotations Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 15/71] mfd: mt6397: Do not call irq_domain_remove if PMIC unsupported Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 16/71] mfd: ab8500-core: Return zero in get_register_interruptible() Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 17/71] mfd: bd9571mwv: Add volatile register to make DVFS work Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 18/71] mfd: qcom_rpm: write fw_version to CTRL_REG Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 19/71] mfd: wm5110: Add missing ASRC rate register Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 20/71] mfd: tps65218: Use devm_regmap_add_irq_chip and clean up error path in probe() Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 21/71] mfd: mc13xxx: Fix a missing check of a register-read failure Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 22/71] xen/pvcalls: remove set but not used variable intf Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 23/71] qed: Fix qed_chain_set_prod() for PBL chains with non power of 2 page count Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 24/71] qed: Fix qed_ll2_post_rx_buffer_notify_fw() by adding a write memory barrier Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 25/71] net: hns: Fix use after free identified by SLUB debug Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 26/71] MIPS: ath79: Enable OF serial ports in the default config Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 27/71] netfilter: nf_tables: fix leaking object reference count Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 28/71] scsi: qla4xxx: check return code of qla4xxx_copy_from_fwddb_param Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 29/71] scsi: isci: initialize shost fully before calling scsi_add_host() Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 30/71] MIPS: jazz: fix 64bit build Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 31/71] bpf: correctly set initial window on active Fast Open sender Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 32/71] net: stmmac: Fix PCI module removal leak Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 33/71] isdn: i4l: isdn_tty: Fix some concurrency double-free bugs Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 34/71] scsi: ufs: Fix system suspend status Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 35/71] scsi: qedi: Add ep_state for login completion on un-reachable targets Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 36/71] always clear the X2APIC_ENABLE bit for PV guest Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 37/71] drm/meson: add missing of_node_put Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 38/71] atm: he: fix sign-extension overflow on large shift Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 39/71] hwmon: (tmp421) Correct the misspelling of the tmp442 compatible attribute in OF device ID table Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 40/71] leds: lp5523: fix a missing check of return value of lp55xx_read Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 41/71] bpf: bpf_setsockopt: reset sock dst on SO_MARK changes Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 42/71] mlxsw: spectrum_switchdev: Do not treat static FDB entries as sticky Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 43/71] net/mlx5e: Fix wrong (zero) TX drop counter indication for representor Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 44/71] isdn: avm: Fix string plus integer warning from Clang Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 45/71] batman-adv: fix uninit-value in batadv_interface_tx() Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 46/71] ipv6: propagate genlmsg_reply return code Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 47/71] net/mlx5e: Dont overwrite pedit action when multiple pedit used Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 48/71] net/packet: fix 4gb buffer limit due to overflow check Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 49/71] net: sfp: do not probe SFP module before were attached Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 50/71] sctp: call gso_reset_checksum when computing checksum in sctp_gso_segment Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 51/71] team: avoid complex list operations in team_nl_cmd_options_set() Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 52/71] sit: check if IPv6 enabled before calling ip6_err_gen_icmpv6_unreach() Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 53/71] net/mlx4_en: Force CHECKSUM_NONE for short ethernet frames Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 54/71] inet_diag: fix reporting cgroup classid and fallback to priority Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 55/71] RDMA/srp: Rework SCSI device reset handling Greg Kroah-Hartman
2019-02-25 21:11 ` [PATCH 4.14 56/71] KEYS: user: Align the payload buffer Greg Kroah-Hartman
2019-02-25 21:11 ` Greg Kroah-Hartman [this message]
2019-02-25 21:12 ` [PATCH 4.14 58/71] parisc: Fix ptrace syscall number modification Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 59/71] ARCv2: Enable unaligned access in early ASM code Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 60/71] ARC: U-boot: check arguments paranoidly Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 61/71] ARC: define ARCH_SLAB_MINALIGN = 8 Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 62/71] drm/i915/fbdev: Actually configure untiled displays Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 63/71] net: validate untrusted gso packets without csum offload Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 64/71] net: avoid false positives in untrusted gso validation Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 65/71] Revert "bridge: do not add port to router list when receives query with source 0.0.0.0" Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 66/71] netfilter: nf_tables: fix flush after rule deletion in the same batch Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 67/71] netfilter: nft_compat: use-after-free when deleting targets Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 68/71] netfilter: ipv6: Dont preserve original oif for loopback address Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 69/71] pinctrl: max77620: Use define directive for max77620_pinconf_param values Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 70/71] phy: tegra: remove redundant self assignment of map Greg Kroah-Hartman
2019-02-25 21:12 ` [PATCH 4.14 71/71] sched/sysctl: Fix attributes of some extern declarations Greg Kroah-Hartman
2019-02-26 8:44 ` [PATCH 4.14 00/71] 4.14.104-stable review Naresh Kamboju
2019-02-26 12:24 ` Jon Hunter
2019-02-26 14:20 ` kernelci.org bot
2019-02-26 15:40 ` shuah
2019-02-26 17:46 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190225195038.930280539@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=dhowells@redhat.com \
--cc=ebiggers@google.com \
--cc=james.morris@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+ec24e95ea483de0a24da@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).