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+399c44bf1f43b8747403@syzkaller.appspotmail.com,
syzbot+e4b12d8d202701f08b6d@syzkaller.appspotmail.com,
Paul Moore <paul@paul-moore.com>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.9 49/88] audit: always check the netlink payload length in audit_receive_msg()
Date: Tue, 10 Mar 2020 13:38:57 +0100 [thread overview]
Message-ID: <20200310123618.260904337@linuxfoundation.org> (raw)
In-Reply-To: <20200310123606.543939933@linuxfoundation.org>
From: Paul Moore <paul@paul-moore.com>
[ Upstream commit 756125289285f6e55a03861bf4b6257aa3d19a93 ]
This patch ensures that we always check the netlink payload length
in audit_receive_msg() before we take any action on the payload
itself.
Cc: stable@vger.kernel.org
Reported-by: syzbot+399c44bf1f43b8747403@syzkaller.appspotmail.com
Reported-by: syzbot+e4b12d8d202701f08b6d@syzkaller.appspotmail.com
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/audit.c | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/kernel/audit.c b/kernel/audit.c
index 3461a3d874fed..53dcaa3b67bcf 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -751,13 +751,11 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature
audit_log_end(ab);
}
-static int audit_set_feature(struct sk_buff *skb)
+static int audit_set_feature(struct audit_features *uaf)
{
- struct audit_features *uaf;
int i;
BUILD_BUG_ON(AUDIT_LAST_FEATURE + 1 > ARRAY_SIZE(audit_feature_names));
- uaf = nlmsg_data(nlmsg_hdr(skb));
/* if there is ever a version 2 we should handle that here */
@@ -823,6 +821,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{
u32 seq;
void *data;
+ int data_len;
int err;
struct audit_buffer *ab;
u16 msg_type = nlh->nlmsg_type;
@@ -846,6 +845,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
}
seq = nlh->nlmsg_seq;
data = nlmsg_data(nlh);
+ data_len = nlmsg_len(nlh);
switch (msg_type) {
case AUDIT_GET: {
@@ -867,7 +867,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
struct audit_status s;
memset(&s, 0, sizeof(s));
/* guard against past and future API changes */
- memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
+ memcpy(&s, data, min_t(size_t, sizeof(s), data_len));
if (s.mask & AUDIT_STATUS_ENABLED) {
err = audit_set_enabled(s.enabled);
if (err < 0)
@@ -930,7 +930,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
return err;
break;
case AUDIT_SET_FEATURE:
- err = audit_set_feature(skb);
+ if (data_len < sizeof(struct audit_features))
+ return -EINVAL;
+ err = audit_set_feature(data);
if (err)
return err;
break;
@@ -942,6 +944,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
err = audit_filter(msg_type, AUDIT_FILTER_USER);
if (err == 1) { /* match or error */
+ char *str = data;
+
err = 0;
if (msg_type == AUDIT_USER_TTY) {
err = tty_audit_push();
@@ -950,19 +954,17 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
}
mutex_unlock(&audit_cmd_mutex);
audit_log_common_recv_msg(&ab, msg_type);
- if (msg_type != AUDIT_USER_TTY)
+ if (msg_type != AUDIT_USER_TTY) {
+ /* ensure NULL termination */
+ str[data_len - 1] = '\0';
audit_log_format(ab, " msg='%.*s'",
AUDIT_MESSAGE_TEXT_MAX,
- (char *)data);
- else {
- int size;
-
+ str);
+ } else {
audit_log_format(ab, " data=");
- size = nlmsg_len(nlh);
- if (size > 0 &&
- ((unsigned char *)data)[size - 1] == '\0')
- size--;
- audit_log_n_untrustedstring(ab, data, size);
+ if (data_len > 0 && str[data_len - 1] == '\0')
+ data_len--;
+ audit_log_n_untrustedstring(ab, str, data_len);
}
audit_set_portid(ab, NETLINK_CB(skb).portid);
audit_log_end(ab);
@@ -971,7 +973,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
break;
case AUDIT_ADD_RULE:
case AUDIT_DEL_RULE:
- if (nlmsg_len(nlh) < sizeof(struct audit_rule_data))
+ if (data_len < sizeof(struct audit_rule_data))
return -EINVAL;
if (audit_enabled == AUDIT_LOCKED) {
audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE);
@@ -980,7 +982,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
return -EPERM;
}
err = audit_rule_change(msg_type, NETLINK_CB(skb).portid,
- seq, data, nlmsg_len(nlh));
+ seq, data, data_len);
break;
case AUDIT_LIST_RULES:
err = audit_list_rules_send(skb, seq);
@@ -994,7 +996,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
case AUDIT_MAKE_EQUIV: {
void *bufp = data;
u32 sizes[2];
- size_t msglen = nlmsg_len(nlh);
+ size_t msglen = data_len;
char *old, *new;
err = -EINVAL;
@@ -1070,7 +1072,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
memset(&s, 0, sizeof(s));
/* guard against past and future API changes */
- memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
+ memcpy(&s, data, min_t(size_t, sizeof(s), data_len));
/* check if new data is valid */
if ((s.enabled != 0 && s.enabled != 1) ||
(s.log_passwd != 0 && s.log_passwd != 1))
--
2.20.1
next prev parent reply other threads:[~2020-03-10 13:34 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-10 12:38 [PATCH 4.9 00/88] 4.9.216-stable review Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 01/88] iwlwifi: pcie: fix rb_allocator workqueue allocation Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 02/88] ext4: fix potential race between online resizing and write operations Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 03/88] ext4: fix potential race between s_flex_groups online resizing and access Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 04/88] ext4: fix potential race between s_group_info " Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 05/88] ipmi:ssif: Handle a possible NULL pointer reference Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 06/88] drm/msm: Set dma maximum segment size for mdss Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 07/88] mac80211: consider more elements in parsing CRC Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 08/88] cfg80211: check wiphy driver existence for drvinfo report Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 09/88] qmi_wwan: re-add DW5821e pre-production variant Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 10/88] net: ena: fix potential crash when rxfh key is NULL Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 11/88] net: ena: add missing ethtool TX timestamping indication Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 12/88] net: ena: fix incorrect default RSS key Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 13/88] net: ena: rss: fix failure to get indirection table Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 14/88] net: ena: rss: store hash function as values and not bits Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 15/88] net: ena: fix incorrectly saving queue numbers when setting RSS indirection table Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 16/88] net: ena: ena-com.c: prevent NULL pointer dereference Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 17/88] cifs: Fix mode output in debugging statements Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 18/88] cfg80211: add missing policy for NL80211_ATTR_STATUS_CODE Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 19/88] sysrq: Restore original console_loglevel when sysrq disabled Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 20/88] sysrq: Remove duplicated sysrq message Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 21/88] net: fib_rules: Correctly set table field when table number exceeds 8 bits Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 22/88] net: phy: restore mdio regs in the iproc mdio driver Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 23/88] ipv6: Fix nlmsg_flags when splitting a multipath route Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 24/88] ipv6: Fix route replacement with dev-only route Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 25/88] sctp: move the format error check out of __sctp_sf_do_9_1_abort Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 26/88] nfc: pn544: Fix occasional HW initialization failure Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 27/88] net: sched: correct flower port blocking Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 28/88] ext4: potential crash on allocation error in ext4_alloc_flex_bg_array() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 29/88] audit: fix error handling in audit_data_to_entry() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 30/88] ACPICA: Introduce ACPI_ACCESS_BYTE_WIDTH() macro Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 31/88] ACPI: watchdog: Fix gas->access_width usage Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 32/88] HID: core: fix off-by-one memset in hid_report_raw_event() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 33/88] HID: core: increase HID report buffer size to 8KiB Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 34/88] HID: hiddev: Fix race in in hiddev_disconnect() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 35/88] MIPS: VPE: Fix a double free and a memory leak in release_vpe() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 36/88] i2c: jz4780: silence log flood on txabrt Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 37/88] ecryptfs: Fix up bad backport of fe2e082f5da5b4a0a92ae32978f81507ef37ec66 Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 38/88] serial: 8250: Check UPF_IRQ_SHARED in advance Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 39/88] include/linux/bitops.h: introduce BITS_PER_TYPE Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 40/88] net: netlink: cap max groups which will be considered in netlink_bind() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 41/88] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 42/88] namei: only return -ECHILD from follow_dotdot_rcu() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 43/88] KVM: Check for a bad hva before dropping into the ghc slow path Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 44/88] slip: stop double free sl->dev in slip_open Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 45/88] tuntap: correctly set SOCKWQ_ASYNC_NOSPACE Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 46/88] drivers: net: xgene: Fix the order of the arguments of alloc_etherdev_mqs() Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 47/88] perf hists browser: Restore ESC as "Zoom out" of DSO/thread/etc Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 48/88] mm/huge_memory.c: use head to check huge zero page Greg Kroah-Hartman
2020-03-10 12:38 ` Greg Kroah-Hartman [this message]
2020-03-10 12:38 ` [PATCH 4.9 50/88] vhost: Check docket sk_family instead of call getname Greg Kroah-Hartman
2020-03-10 12:38 ` [PATCH 4.9 51/88] serial: ar933x_uart: set UART_CS_{RX,TX}_READY_ORIDE Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 52/88] usb: gadget: composite: Support more than 500mA MaxPower Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 53/88] usb: gadget: ffs: ffs_aio_cancel(): Save/restore IRQ flags Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 54/88] usb: gadget: serial: fix Tx stall after buffer overflow Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 55/88] drm: msm: Fix return type of dsi_mgr_connector_mode_valid for kCFI Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 56/88] drm/msm/dsi: save pll state before dsi host is powered off Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 57/88] net: ks8851-ml: Remove 8-bit bus accessors Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 58/88] net: ks8851-ml: Fix 16-bit data access Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 59/88] net: ks8851-ml: Fix 16-bit IO operation Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 60/88] watchdog: da9062: do not ping the hw during stop() Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 61/88] s390/cio: cio_ignore_proc_seq_next should increase position index Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 62/88] x86/boot/compressed: Dont declare __force_order in kaslr_64.c Greg Kroah-Hartman
2020-03-10 14:33 ` Thomas Voegtle
2020-03-10 15:08 ` Borislav Petkov
2020-03-10 16:55 ` Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 63/88] cifs: dont leak -EAGAIN for stat() during reconnect Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 64/88] usb: storage: Add quirk for Samsung Fit flash Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 65/88] usb: quirks: add NO_LPM quirk for Logitech Screen Share Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 66/88] usb: core: hub: do error out if usb_autopm_get_interface() fails Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 67/88] usb: core: port: " Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 68/88] vgacon: Fix a UAF in vgacon_invert_region Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 69/88] fat: fix uninit-memory access for partial initialized inode Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 70/88] tty:serial:mvebu-uart:fix a wrong return Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 71/88] vt: selection, close sel_buffer race Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 72/88] vt: selection, push console lock down Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 73/88] vt: selection, push sel_lock up Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 74/88] x86/pkeys: Manually set X86_FEATURE_OSPKE to preserve existing changes Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 75/88] dmaengine: tegra-apb: Fix use-after-free Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 76/88] dmaengine: tegra-apb: Prevent race conditions of tasklet vs free list Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 77/88] ARM: dts: ls1021a: Restore MDIO compatible to gianfar Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 78/88] ASoC: pcm: Fix possible buffer overflow in dpcm state sysfs output Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 79/88] ASoC: pcm512x: Fix unbalanced regulator enable call in probe error path Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 80/88] ASoC: dapm: Correct DAPM handling of active widgets during shutdown Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 81/88] RDMA/iwcm: Fix iwcm work deallocation Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 82/88] RMDA/cm: Fix missing ib_cm_destroy_id() in ib_cm_insert_listen() Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 83/88] ARM: imx: build v7_cpu_resume() unconditionally Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 84/88] hwmon: (adt7462) Fix an error return in ADT7462_REG_VOLT() Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 85/88] dmaengine: coh901318: Fix a double lock bug in dma_tc_handle() Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 86/88] powerpc: fix hardware PMU exception bug on PowerVM compatibility mode systems Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 87/88] dm cache: fix a crash due to incorrect work item cancelling Greg Kroah-Hartman
2020-03-10 12:39 ` [PATCH 4.9 88/88] crypto: algif_skcipher - use ZERO_OR_NULL_PTR in skcipher_recvmsg_async Greg Kroah-Hartman
2020-03-10 18:21 ` [PATCH 4.9 00/88] 4.9.216-stable review Naresh Kamboju
2020-03-10 20:07 ` Jon Hunter
2020-03-10 21:32 ` shuah
2020-03-10 21:57 ` 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=20200310123618.260904337@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+399c44bf1f43b8747403@syzkaller.appspotmail.com \
--cc=syzbot+e4b12d8d202701f08b6d@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).