linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jia-Ju Bai <baijiaju1990@gmail.com>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	Junxiao Bi <junxiao.bi@oracle.com>,
	Changwei Ge <gechangwei@live.cn>, Gang He <ghe@suse.com>,
	Jun Piao <piaojun@huawei.com>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.19 081/100] fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()
Date: Fri, 18 Oct 2019 18:05:06 -0400	[thread overview]
Message-ID: <20191018220525.9042-81-sashal@kernel.org> (raw)
In-Reply-To: <20191018220525.9042-1-sashal@kernel.org>

From: Jia-Ju Bai <baijiaju1990@gmail.com>

[ Upstream commit 56e94ea132bb5c2c1d0b60a6aeb34dcb7d71a53d ]

In ocfs2_xa_prepare_entry(), there is an if statement on line 2136 to
check whether loc->xl_entry is NULL:

    if (loc->xl_entry)

When loc->xl_entry is NULL, it is used on line 2158:

    ocfs2_xa_add_entry(loc, name_hash);
        loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
        loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);

and line 2164:

    ocfs2_xa_add_namevalue(loc, xi);
        loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len);
        loc->xl_entry->xe_name_len = xi->xi_name_len;

Thus, possible null-pointer dereferences may occur.

To fix these bugs, if loc-xl_entry is NULL, ocfs2_xa_prepare_entry()
abnormally returns with -EINVAL.

These bugs are found by a static analysis tool STCheck written by us.

[akpm@linux-foundation.org: remove now-unused ocfs2_xa_add_entry()]
Link: http://lkml.kernel.org/r/20190726101447.9153-1-baijiaju1990@gmail.com
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ocfs2/xattr.c | 56 ++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 33 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index c146e12a8601f..0d80e0df6c241 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1498,18 +1498,6 @@ static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc,
 	return loc->xl_ops->xlo_check_space(loc, xi);
 }
 
-static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
-{
-	loc->xl_ops->xlo_add_entry(loc, name_hash);
-	loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
-	/*
-	 * We can't leave the new entry's xe_name_offset at zero or
-	 * add_namevalue() will go nuts.  We set it to the size of our
-	 * storage so that it can never be less than any other entry.
-	 */
-	loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
-}
-
 static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc,
 				   struct ocfs2_xattr_info *xi)
 {
@@ -2141,29 +2129,31 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
 	if (rc)
 		goto out;
 
-	if (loc->xl_entry) {
-		if (ocfs2_xa_can_reuse_entry(loc, xi)) {
-			orig_value_size = loc->xl_entry->xe_value_size;
-			rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
-			if (rc)
-				goto out;
-			goto alloc_value;
-		}
+	if (!loc->xl_entry) {
+		rc = -EINVAL;
+		goto out;
+	}
 
-		if (!ocfs2_xattr_is_local(loc->xl_entry)) {
-			orig_clusters = ocfs2_xa_value_clusters(loc);
-			rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
-			if (rc) {
-				mlog_errno(rc);
-				ocfs2_xa_cleanup_value_truncate(loc,
-								"overwriting",
-								orig_clusters);
-				goto out;
-			}
+	if (ocfs2_xa_can_reuse_entry(loc, xi)) {
+		orig_value_size = loc->xl_entry->xe_value_size;
+		rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
+		if (rc)
+			goto out;
+		goto alloc_value;
+	}
+
+	if (!ocfs2_xattr_is_local(loc->xl_entry)) {
+		orig_clusters = ocfs2_xa_value_clusters(loc);
+		rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
+		if (rc) {
+			mlog_errno(rc);
+			ocfs2_xa_cleanup_value_truncate(loc,
+							"overwriting",
+							orig_clusters);
+			goto out;
 		}
-		ocfs2_xa_wipe_namevalue(loc);
-	} else
-		ocfs2_xa_add_entry(loc, name_hash);
+	}
+	ocfs2_xa_wipe_namevalue(loc);
 
 	/*
 	 * If we get here, we have a blank entry.  Fill it.  We grow our
-- 
2.20.1


  parent reply	other threads:[~2019-10-18 22:07 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 22:03 [PATCH AUTOSEL 4.19 001/100] wil6210: fix freeing of rx buffers in EDMA mode Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 002/100] f2fs: flush quota blocks after turnning it off Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 003/100] scsi: lpfc: Fix a duplicate 0711 log message number Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 004/100] sc16is7xx: Fix for "Unexpected interrupt: 8" Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 005/100] powerpc/powernv: hold device_hotplug_lock when calling memtrace_offline_pages() Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 006/100] f2fs: fix to recover inode's i_gc_failures during POR Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 007/100] f2fs: fix to recover inode->i_flags of inode block " Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 008/100] HID: i2c-hid: add Direkt-Tek DTLAPY133-1 to descriptor override Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 009/100] usb: dwc2: fix unbalanced use of external vbus-supply Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 010/100] tools/power turbostat: fix goldmont C-state limit decoding Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 011/100] x86/cpu: Add Atom Tremont (Jacobsville) Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 012/100] drm/msm/dpu: handle failures while initializing displays Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 013/100] bcache: fix input overflow to writeback_rate_minimum Sasha Levin
2019-10-18 22:03 ` [PATCH AUTOSEL 4.19 014/100] PCI: Fix Switchtec DMA aliasing quirk dmesg noise Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 015/100] Btrfs: fix deadlock on tree root leaf when finding free extent Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 016/100] netfilter: ipset: Make invalid MAC address checks consistent Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 017/100] HID: i2c-hid: Disable runtime PM for LG touchscreen Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 018/100] HID: i2c-hid: Ignore input report if there's no data present on Elan touchpanels Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 019/100] HID: i2c-hid: Add Odys Winbook 13 to descriptor override Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 020/100] platform/x86: Add the VLV ISP PCI ID to atomisp2_pm Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 021/100] platform/x86: Fix config space access for intel_atomisp2_pm Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 022/100] ath10k: assign 'n_cipher_suites = 11' for WCN3990 to enable WPA3 Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 023/100] clk: boston: unregister clks on failure in clk_boston_setup() Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 024/100] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 025/100] staging: mt7621-pinctrl: use pinconf-generic for 'dt_node_to_map' and 'dt_free_map' Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 026/100] HID: Add ASUS T100CHI keyboard dock battery quirks Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 027/100] NFSv4: Ensure that the state manager exits the loop on SIGKILL Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 028/100] HID: steam: fix boot loop with bluetooth firmware Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 029/100] HID: steam: fix deadlock with input devices Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 030/100] samples: bpf: fix: seg fault with NULL pointer arg Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 031/100] usb: dwc3: gadget: early giveback if End Transfer already completed Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 032/100] usb: dwc3: gadget: clear DWC3_EP_TRANSFER_STARTED on cmd complete Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 033/100] ALSA: usb-audio: Add quirk for MOTU MicroBook II Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 034/100] ALSA: usb-audio: Cleanup DSD whitelist Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 035/100] usb: handle warm-reset port requests on hub resume Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 036/100] rtc: pcf8523: set xtal load capacitance from DT Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 037/100] mlxsw: spectrum: Set LAG port collector only when active Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 038/100] net: stmmac: Fix NAPI poll in TX path when in multi-queue Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 039/100] scsi: lpfc: Correct localport timeout duration error Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 040/100] CIFS: Respect SMB2 hdr preamble size in read responses Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 041/100] cifs: add credits from unmatched responses/messages Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 042/100] ALSA: hda/realtek - Apply ALC294 hp init also for S4 resume Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 043/100] media: vimc: Remove unused but set variables Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 044/100] ext4: disallow files with EXT4_JOURNAL_DATA_FL from EXT4_IOC_SWAP_BOOT Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 045/100] exec: load_script: Do not exec truncated interpreter path Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 046/100] net: dsa: mv88e6xxx: Release lock while requesting IRQ Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 047/100] PCI/PME: Fix possible use-after-free on remove Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 048/100] drm/amd/display: fix odm combine pipe reset Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 049/100] power: supply: max14656: fix potential use-after-free Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 050/100] iio: adc: meson_saradc: Fix memory allocation order Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 051/100] iio: fix center temperature of bmc150-accel-core Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 052/100] libsubcmd: Make _FORTIFY_SOURCE defines dependent on the feature Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 053/100] perf tests: Avoid raising SEGV using an obvious NULL dereference Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 054/100] perf map: Fix overlapped map handling Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 055/100] perf script brstackinsn: Fix recovery from LBR/binary mismatch Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 056/100] perf jevents: Fix period for Intel fixed counters Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 057/100] perf tools: Propagate get_cpuid() error Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 058/100] perf annotate: Propagate perf_env__arch() error Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 059/100] perf annotate: Fix the signedness of failure returns Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 060/100] perf annotate: Propagate the symbol__annotate() error return Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 061/100] perf annotate: Return appropriate error code for allocation failures Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 062/100] staging: rtl8188eu: fix null dereference when kzalloc fails Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 063/100] crypto: arm/aes-ce - add dependency on AES library Sasha Levin
2019-10-21  6:08   ` Ard Biesheuvel
2019-10-29  9:19     ` Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 064/100] RDMA/hfi1: Prevent memory leak in sdma_init Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 065/100] RDMA/iwcm: Fix a lock inversion issue Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 066/100] HID: hyperv: Use in-place iterator API in the channel callback Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 067/100] nfs: Fix nfsi->nrequests count error on nfs_inode_remove_request Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 068/100] arm64: ftrace: Ensure synchronisation in PLT setup for Neoverse-N1 #1542419 Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 069/100] tty: serial: owl: Fix the link time qualifier of 'owl_uart_exit()' Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 070/100] tty: n_hdlc: fix build on SPARC Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 071/100] RDMA/cxgb4: Do not dma memory off of the stack Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 072/100] gpio: max77620: Use correct unit for debounce times Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 073/100] fs: cifs: mute -Wunused-const-variable message Sasha Levin
2019-10-18 22:04 ` [PATCH AUTOSEL 4.19 074/100] serial: mctrl_gpio: Check for NULL pointer Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 075/100] efi/cper: Fix endianness of PCIe class code Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 076/100] efi/x86: Do not clean dummy variable in kexec path Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 077/100] kbuild: fix build error of 'make nsdeps' in clean tree Sasha Levin
2019-10-19  0:13   ` Masahiro Yamada
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 078/100] MIPS: include: Mark __cmpxchg as __always_inline Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 079/100] x86/xen: Return from panic notifier Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 080/100] ocfs2: clear zero in unaligned direct IO Sasha Levin
2019-10-18 22:05 ` Sasha Levin [this message]
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 082/100] fs: ocfs2: fix a possible null-pointer dereference in ocfs2_write_end_nolock() Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 083/100] fs: ocfs2: fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc() Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 084/100] arm64: armv8_deprecated: Checking return value for memory allocation Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 085/100] x86/cpu: Add Comet Lake to the Intel CPU models header Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 086/100] sched/vtime: Fix guest/system mis-accounting on task switch Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 087/100] perf/x86/amd: Change/fix NMI latency mitigation to use a timestamp Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 088/100] drm/amdgpu: fix memory leak Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 089/100] iio: adc: hx711: fix bug in sampling of data Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 090/100] iio: imu: adis16400: release allocated memory on failure Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 091/100] iio: adc: ad799x: fix probe error handling Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 092/100] iio: light: opt3001: fix mutex unlock race Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 093/100] MIPS: include: Mark __xchg as __always_inline Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 094/100] MIPS: fw: sni: Fix out of bounds init of o32 stack Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 095/100] USB: usb-skeleton: fix use-after-free after driver unbind Sasha Levin
2019-10-18 22:22   ` Greg Kroah-Hartman
2019-10-29  9:04     ` Sasha Levin
2019-10-29  9:43       ` Greg Kroah-Hartman
2019-10-29 10:04         ` Johan Hovold
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 096/100] virt: vbox: fix memory leak in hgcm_call_preprocess_linaddr Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 097/100] nbd: fix possible sysfs duplicate warning Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 098/100] NFSv4: Fix leak of clp->cl_acceptor string Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 099/100] s390/uaccess: avoid (false positive) compiler warnings Sasha Levin
2019-10-18 22:05 ` [PATCH AUTOSEL 4.19 100/100] tracing: Initialize iter->seq after zeroing in tracing_read_pipe() Sasha Levin

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=20191018220525.9042-81-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baijiaju1990@gmail.com \
    --cc=gechangwei@live.cn \
    --cc=ghe@suse.com \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=junxiao.bi@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=piaojun@huawei.com \
    --cc=sfr@canb.auug.org.au \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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).