* [PATCH 0/2] pipe: Fix a potential UAF and delete a duplicate line of code
@ 2021-11-15 3:57 Zhen Lei
2021-11-15 3:57 ` [PATCH 1/2] pipe: fix potential use-after-free in pipe_read() Zhen Lei
2021-11-15 3:57 ` [PATCH 2/2] pipe: delete a duplicate line of code in pipe_write() Zhen Lei
0 siblings, 2 replies; 7+ messages in thread
From: Zhen Lei @ 2021-11-15 3:57 UTC (permalink / raw)
To: Alexander Viro, David Howells, linux-fsdevel, linux-kernel; +Cc: Zhen Lei
I found these when I was learning the code. I briefly tested it, and no new
problems were introduced.
Zhen Lei (2):
pipe: fix potential use-after-free in pipe_read()
pipe: delete a duplicate line of code in pipe_write()
fs/pipe.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--
2.26.0.106.g9fadedd
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] pipe: fix potential use-after-free in pipe_read()
2021-11-15 3:57 [PATCH 0/2] pipe: Fix a potential UAF and delete a duplicate line of code Zhen Lei
@ 2021-11-15 3:57 ` Zhen Lei
2021-11-15 4:25 ` Matthew Wilcox
2021-11-15 3:57 ` [PATCH 2/2] pipe: delete a duplicate line of code in pipe_write() Zhen Lei
1 sibling, 1 reply; 7+ messages in thread
From: Zhen Lei @ 2021-11-15 3:57 UTC (permalink / raw)
To: Alexander Viro, David Howells, linux-fsdevel, linux-kernel; +Cc: Zhen Lei
Accessing buf->flags after pipe_buf_release(pipe, buf) is unsafe, because
the 'buf' memory maybe freed.
Fixes: e7d553d69cf6 ("pipe: Add notification lossage handling")
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
fs/pipe.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index 6d4342bad9f15b2..302f1e50ce3be1d 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -319,10 +319,12 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
}
if (!buf->len) {
+ unsigned int __maybe_unused flags = buf->flags;
+
pipe_buf_release(pipe, buf);
spin_lock_irq(&pipe->rd_wait.lock);
#ifdef CONFIG_WATCH_QUEUE
- if (buf->flags & PIPE_BUF_FLAG_LOSS)
+ if (flags & PIPE_BUF_FLAG_LOSS)
pipe->note_loss = true;
#endif
tail++;
--
2.26.0.106.g9fadedd
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] pipe: delete a duplicate line of code in pipe_write()
2021-11-15 3:57 [PATCH 0/2] pipe: Fix a potential UAF and delete a duplicate line of code Zhen Lei
2021-11-15 3:57 ` [PATCH 1/2] pipe: fix potential use-after-free in pipe_read() Zhen Lei
@ 2021-11-15 3:57 ` Zhen Lei
1 sibling, 0 replies; 7+ messages in thread
From: Zhen Lei @ 2021-11-15 3:57 UTC (permalink / raw)
To: Alexander Viro, David Howells, linux-fsdevel, linux-kernel; +Cc: Zhen Lei
The buf->offset has been assigned to 0 before the copy operation, and it
seems odd to readjust its value after the copy is complete. Delete the
second 'buf->offset = 0'.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
fs/pipe.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index 302f1e50ce3be1d..7ba11a633c0eeb9 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -536,7 +536,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
break;
}
ret += copied;
- buf->offset = 0;
buf->len = copied;
if (!iov_iter_count(from))
--
2.26.0.106.g9fadedd
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] pipe: fix potential use-after-free in pipe_read()
2021-11-15 3:57 ` [PATCH 1/2] pipe: fix potential use-after-free in pipe_read() Zhen Lei
@ 2021-11-15 4:25 ` Matthew Wilcox
2021-11-15 6:13 ` Leizhen (ThunderTown)
0 siblings, 1 reply; 7+ messages in thread
From: Matthew Wilcox @ 2021-11-15 4:25 UTC (permalink / raw)
To: Zhen Lei; +Cc: Alexander Viro, David Howells, linux-fsdevel, linux-kernel
On Mon, Nov 15, 2021 at 11:57:20AM +0800, Zhen Lei wrote:
> if (!buf->len) {
> + unsigned int __maybe_unused flags = buf->flags;
Why __maybe_unused?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] pipe: fix potential use-after-free in pipe_read()
2021-11-15 4:25 ` Matthew Wilcox
@ 2021-11-15 6:13 ` Leizhen (ThunderTown)
2021-11-15 13:05 ` Matthew Wilcox
0 siblings, 1 reply; 7+ messages in thread
From: Leizhen (ThunderTown) @ 2021-11-15 6:13 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Alexander Viro, David Howells, linux-fsdevel, linux-kernel
On 2021/11/15 12:25, Matthew Wilcox wrote:
> On Mon, Nov 15, 2021 at 11:57:20AM +0800, Zhen Lei wrote:
>> if (!buf->len) {
>> + unsigned int __maybe_unused flags = buf->flags;
>
> Why __maybe_unused?
It's used only if "#ifdef CONFIG_WATCH_QUEUE". Otherwise, a warning will be reported.
> .
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] pipe: fix potential use-after-free in pipe_read()
2021-11-15 6:13 ` Leizhen (ThunderTown)
@ 2021-11-15 13:05 ` Matthew Wilcox
2021-11-23 1:09 ` Leizhen (ThunderTown)
0 siblings, 1 reply; 7+ messages in thread
From: Matthew Wilcox @ 2021-11-15 13:05 UTC (permalink / raw)
To: Leizhen (ThunderTown)
Cc: Alexander Viro, David Howells, linux-fsdevel, linux-kernel
On Mon, Nov 15, 2021 at 02:13:44PM +0800, Leizhen (ThunderTown) wrote:
>
>
> On 2021/11/15 12:25, Matthew Wilcox wrote:
> > On Mon, Nov 15, 2021 at 11:57:20AM +0800, Zhen Lei wrote:
> >> if (!buf->len) {
> >> + unsigned int __maybe_unused flags = buf->flags;
> >
> > Why __maybe_unused?
>
> It's used only if "#ifdef CONFIG_WATCH_QUEUE". Otherwise, a warning will be reported.
Better to turn the #ifdef into if (IS_ENABLED())
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] pipe: fix potential use-after-free in pipe_read()
2021-11-15 13:05 ` Matthew Wilcox
@ 2021-11-23 1:09 ` Leizhen (ThunderTown)
0 siblings, 0 replies; 7+ messages in thread
From: Leizhen (ThunderTown) @ 2021-11-23 1:09 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Alexander Viro, David Howells, linux-fsdevel, linux-kernel
On 2021/11/15 21:05, Matthew Wilcox wrote:
> On Mon, Nov 15, 2021 at 02:13:44PM +0800, Leizhen (ThunderTown) wrote:
>>
>>
>> On 2021/11/15 12:25, Matthew Wilcox wrote:
>>> On Mon, Nov 15, 2021 at 11:57:20AM +0800, Zhen Lei wrote:
>>>> if (!buf->len) {
>>>> + unsigned int __maybe_unused flags = buf->flags;
>>>
>>> Why __maybe_unused?
>>
>> It's used only if "#ifdef CONFIG_WATCH_QUEUE". Otherwise, a warning will be reported.
>
> Better to turn the #ifdef into if (IS_ENABLED())
Hi, Matthew:
Thank you for your advice. IS_ENABLED() is a good idea, but when I tried it, I found that
the macro 'PIPE_BUF_FLAG_LOSS' and the structure member 'note_loss' were also separated by
"ifdef CONFIG_WATCH_QUEUE", so this method is not suitable here.
#ifdef CONFIG_WATCH_QUEUE
#define PIPE_BUF_FLAG_LOSS 0x40 /* Message loss happened after this buffer */
#endif
@@ -62,9 +60,7 @@ struct pipe_inode_info {
unsigned int tail;
unsigned int max_usage;
unsigned int ring_size;
#ifdef CONFIG_WATCH_QUEUE
bool note_loss;
#endif
> .
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-11-23 1:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 3:57 [PATCH 0/2] pipe: Fix a potential UAF and delete a duplicate line of code Zhen Lei
2021-11-15 3:57 ` [PATCH 1/2] pipe: fix potential use-after-free in pipe_read() Zhen Lei
2021-11-15 4:25 ` Matthew Wilcox
2021-11-15 6:13 ` Leizhen (ThunderTown)
2021-11-15 13:05 ` Matthew Wilcox
2021-11-23 1:09 ` Leizhen (ThunderTown)
2021-11-15 3:57 ` [PATCH 2/2] pipe: delete a duplicate line of code in pipe_write() Zhen Lei
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).