From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Jann Horn <jannh@google.com>,
Matthew Wilcox <willy@infradead.org>,
stable@kernel.org, Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.19 06/72] fs: prevent page refcount overflow in pipe_buf_get
Date: Thu, 2 May 2019 17:20:28 +0200 [thread overview]
Message-ID: <20190502143333.929606334@linuxfoundation.org> (raw)
In-Reply-To: <20190502143333.437607839@linuxfoundation.org>
From: Matthew Wilcox <willy@infradead.org>
commit 15fab63e1e57be9fdb5eec1bbc5916e9825e9acb upstream.
Change pipe_buf_get() to return a bool indicating whether it succeeded
in raising the refcount of the page (if the thing in the pipe is a page).
This removes another mechanism for overflowing the page refcount. All
callers converted to handle a failure.
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/fuse/dev.c | 12 ++++++------
fs/pipe.c | 4 ++--
fs/splice.c | 12 ++++++++++--
include/linux/pipe_fs_i.h | 10 ++++++----
kernel/trace/trace.c | 6 +++++-
5 files changed, 29 insertions(+), 15 deletions(-)
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1989,10 +1989,8 @@ static ssize_t fuse_dev_splice_write(str
rem += pipe->bufs[(pipe->curbuf + idx) & (pipe->buffers - 1)].len;
ret = -EINVAL;
- if (rem < len) {
- pipe_unlock(pipe);
- goto out;
- }
+ if (rem < len)
+ goto out_free;
rem = len;
while (rem) {
@@ -2010,7 +2008,9 @@ static ssize_t fuse_dev_splice_write(str
pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
pipe->nrbufs--;
} else {
- pipe_buf_get(pipe, ibuf);
+ if (!pipe_buf_get(pipe, ibuf))
+ goto out_free;
+
*obuf = *ibuf;
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
obuf->len = rem;
@@ -2033,11 +2033,11 @@ static ssize_t fuse_dev_splice_write(str
ret = fuse_dev_do_write(fud, &cs, len);
pipe_lock(pipe);
+out_free:
for (idx = 0; idx < nbuf; idx++)
pipe_buf_release(pipe, &bufs[idx]);
pipe_unlock(pipe);
-out:
kvfree(bufs);
return ret;
}
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -189,9 +189,9 @@ EXPORT_SYMBOL(generic_pipe_buf_steal);
* in the tee() system call, when we duplicate the buffers in one
* pipe into another.
*/
-void generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
+bool generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
{
- get_page(buf->page);
+ return try_get_page(buf->page);
}
EXPORT_SYMBOL(generic_pipe_buf_get);
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1584,7 +1584,11 @@ retry:
* Get a reference to this pipe buffer,
* so we can copy the contents over.
*/
- pipe_buf_get(ipipe, ibuf);
+ if (!pipe_buf_get(ipipe, ibuf)) {
+ if (ret == 0)
+ ret = -EFAULT;
+ break;
+ }
*obuf = *ibuf;
/*
@@ -1658,7 +1662,11 @@ static int link_pipe(struct pipe_inode_i
* Get a reference to this pipe buffer,
* so we can copy the contents over.
*/
- pipe_buf_get(ipipe, ibuf);
+ if (!pipe_buf_get(ipipe, ibuf)) {
+ if (ret == 0)
+ ret = -EFAULT;
+ break;
+ }
obuf = opipe->bufs + nbuf;
*obuf = *ibuf;
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -108,18 +108,20 @@ struct pipe_buf_operations {
/*
* Get a reference to the pipe buffer.
*/
- void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
+ bool (*get)(struct pipe_inode_info *, struct pipe_buffer *);
};
/**
* pipe_buf_get - get a reference to a pipe_buffer
* @pipe: the pipe that the buffer belongs to
* @buf: the buffer to get a reference to
+ *
+ * Return: %true if the reference was successfully obtained.
*/
-static inline void pipe_buf_get(struct pipe_inode_info *pipe,
+static inline __must_check bool pipe_buf_get(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
- buf->ops->get(pipe, buf);
+ return buf->ops->get(pipe, buf);
}
/**
@@ -178,7 +180,7 @@ struct pipe_inode_info *alloc_pipe_info(
void free_pipe_info(struct pipe_inode_info *);
/* Generic pipe buffer ops functions */
-void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
+bool generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
int generic_pipe_buf_confirm(struct pipe_inode_info *, struct pipe_buffer *);
int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
int generic_pipe_buf_nosteal(struct pipe_inode_info *, struct pipe_buffer *);
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6823,12 +6823,16 @@ static void buffer_pipe_buf_release(stru
buf->private = 0;
}
-static void buffer_pipe_buf_get(struct pipe_inode_info *pipe,
+static bool buffer_pipe_buf_get(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
struct buffer_ref *ref = (struct buffer_ref *)buf->private;
+ if (refcount_read(&ref->refcount) > INT_MAX/2)
+ return false;
+
refcount_inc(&ref->refcount);
+ return true;
}
/* Pipe buffer operations for a buffer. */
next prev parent reply other threads:[~2019-05-02 15:45 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 15:20 [PATCH 4.19 00/72] 4.19.39-stable review Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 01/72] selinux: use kernel linux/socket.h for genheaders and mdp Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 02/72] Revert "ACPICA: Clear status of GPEs before enabling them" Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 03/72] mm: make page ref count overflow check tighter and more explicit Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 04/72] mm: add try_get_page() helper function Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 05/72] mm: prevent get_user_pages() from overflowing page refcount Greg Kroah-Hartman
2019-05-02 15:20 ` Greg Kroah-Hartman [this message]
2019-05-02 15:20 ` [PATCH 4.19 07/72] ARM: dts: bcm283x: Fix hdmi hpd gpio pull Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 08/72] s390: limit brk randomization to 32MB Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 09/72] net: ieee802154: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-03 8:32 ` Pavel Machek
2019-05-02 15:20 ` [PATCH 4.19 10/72] ieee802154: hwsim: propagate genlmsg_reply return code Greg Kroah-Hartman
2019-05-03 8:33 ` Pavel Machek
2019-05-02 15:20 ` [PATCH 4.19 11/72] net: stmmac: dont set own bit too early for jumbo frames Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 12/72] qlcnic: Avoid potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 13/72] xsk: fix umem memory leak on cleanup Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 14/72] staging: axis-fifo: add CONFIG_OF dependency Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 15/72] staging, mt7621-pci: fix build without pci support Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 16/72] netfilter: nft_set_rbtree: check for inactive element after flag mismatch Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 17/72] netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 18/72] netfilter: fix NETFILTER_XT_TARGET_TEE dependencies Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 19/72] netfilter: ip6t_srh: fix NULL pointer dereferences Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 20/72] s390/qeth: fix race when initializing the IP address table Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 21/72] ARM: imx51: fix a leaked reference by adding missing of_node_put Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 22/72] sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init() Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 23/72] serial: ar933x_uart: Fix build failure with disabled console Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 24/72] KVM: arm64: Reset the PMU in preemptible context Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 25/72] KVM: arm/arm64: vgic-its: Take the srcu lock when writing to guest memory Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 26/72] KVM: arm/arm64: vgic-its: Take the srcu lock when parsing the memslots Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 27/72] usb: dwc3: pci: add support for Comet Lake PCH ID Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 28/72] usb: gadget: net2280: Fix overrun of OUT messages Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 29/72] usb: gadget: net2280: Fix net2280_dequeue() Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 30/72] usb: gadget: net2272: Fix net2272_dequeue() Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 31/72] ARM: dts: pfla02: increase phy reset duration Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 32/72] i2c: i801: Add support for Intel Comet Lake Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 33/72] net: ks8851: Dequeue RX packets explicitly Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 34/72] net: ks8851: Reassert reset pin if chip ID check fails Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 35/72] net: ks8851: Delay requesting IRQ until opened Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 36/72] net: ks8851: Set initial carrier state to down Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 37/72] staging: rtl8188eu: Fix potential NULL pointer dereference of kcalloc Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 38/72] staging: rtlwifi: rtl8822b: fix to avoid potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 39/72] staging: rtl8712: uninitialized memory in read_bbreg_hdl() Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 40/72] staging: rtlwifi: Fix potential NULL pointer dereference of kzalloc Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 41/72] net: macb: Add null check for PCLK and HCLK Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 42/72] net/sched: dont dereference a->goto_chain to read the chain index Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 43/72] ARM: dts: imx6qdl: Fix typo in imx6qdl-icore-rqs.dtsi Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 44/72] drm/tegra: hub: Fix dereference before check Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 45/72] NFS: Fix a typo in nfs_init_timeout_values() Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 46/72] net: xilinx: fix possible object reference leak Greg Kroah-Hartman
2019-05-03 10:08 ` Pavel Machek
[not found] ` <201905051417486865228@zte.com.cn>
2019-05-06 17:48 ` [PATCH 4.19 46/72] net: xilinx: fix possible object referenceleak Pavel Machek
2019-05-02 15:21 ` [PATCH 4.19 47/72] net: ibm: fix possible object reference leak Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 48/72] net: ethernet: ti: " Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 49/72] drm: Fix drm_release() and device unplug Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 50/72] gpio: aspeed: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 51/72] drm/meson: Fix invalid pointer in meson_drv_unbind() Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 52/72] drm/meson: Uninstall IRQ handler Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 53/72] ARM: davinci: fix build failure with allnoconfig Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 54/72] scsi: mpt3sas: Fix kernel panic during expander reset Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 55/72] scsi: aacraid: Insure we dont access PCIe space during AER/EEH Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 56/72] scsi: qla4xxx: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 57/72] usb: usb251xb: fix to avoid " Greg Kroah-Hartman
2019-05-03 21:32 ` Pavel Machek
2019-05-04 6:45 ` Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 58/72] leds: trigger: netdev: fix refcnt leak on interface rename Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 59/72] x86/realmode: Dont leak the trampoline kernel address Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 60/72] usb: u132-hcd: fix resource leak Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 61/72] ceph: fix use-after-free on symlink traversal Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 62/72] scsi: zfcp: reduce flood of fcrscn1 trace records on multi-element RSCN Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 63/72] x86/mm: Dont exceed the valid physical address space Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 64/72] libata: fix using DMA buffers on stack Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 65/72] gpio: of: Fix of_gpiochip_add() error path Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 66/72] nvme-multipath: relax ANA state check Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 67/72] perf machine: Update kernel map address and re-order properly Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 68/72] kconfig/[mn]conf: handle backspace (^H) key Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 69/72] iommu/amd: Reserve exclusion range in iova-domain Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 70/72] ptrace: take into account saved_sigmask in PTRACE{GET,SET}SIGMASK Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 71/72] leds: pca9532: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 72/72] leds: trigger: netdev: use memcpy in device_name_store Greg Kroah-Hartman
2019-05-02 22:46 ` [PATCH 4.19 00/72] 4.19.39-stable review kernelci.org bot
2019-05-03 7:26 ` Naresh Kamboju
2019-05-03 9:27 ` Jon Hunter
2019-05-03 17:16 ` Guenter Roeck
2019-05-03 21:20 ` shuah
2019-05-04 6:54 ` Pavel Machek
2019-05-04 7:18 ` Greg Kroah-Hartman
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=20190502143333.929606334@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.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).