提交 3354447a 编写于 作者: X Xiyu Yang 提交者: Yongqiang Liu

ext4: convert from atomic_t to refcount_t on ext4_io_end->count

hulk inclusion
category: bugfix
bugzilla: 186971, https://gitee.com/openeuler/kernel/issues/I5C8IW
CVE: NA

--------------------------------

refcount_t type and corresponding API can protect refcounters from
accidental underflow and overflow and further use-after-free situations.
Signed-off-by: NXiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: NXin Tan <tanxin.ctf@gmail.com>
Reviewed-by: NJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/1626674355-55795-1-git-send-email-xiyuyang19@fudan.edu.cnSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
Signed-off-by: NLi Nan <linan122@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 2105af3b
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#ifndef _EXT4_H #ifndef _EXT4_H
#define _EXT4_H #define _EXT4_H
#include <linux/refcount.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/magic.h> #include <linux/magic.h>
...@@ -231,7 +232,7 @@ typedef struct ext4_io_end { ...@@ -231,7 +232,7 @@ typedef struct ext4_io_end {
struct bio *bio; /* Linked list of completed struct bio *bio; /* Linked list of completed
* bios covering the extent */ * bios covering the extent */
unsigned int flag; /* unwritten or not */ unsigned int flag; /* unwritten or not */
atomic_t count; /* reference counter */ refcount_t count; /* reference counter */
loff_t offset; /* offset in the file */ loff_t offset; /* offset in the file */
ssize_t size; /* size of the extent */ ssize_t size; /* size of the extent */
} ext4_io_end_t; } ext4_io_end_t;
......
...@@ -256,14 +256,14 @@ ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags) ...@@ -256,14 +256,14 @@ ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags)
if (io) { if (io) {
io->inode = inode; io->inode = inode;
INIT_LIST_HEAD(&io->list); INIT_LIST_HEAD(&io->list);
atomic_set(&io->count, 1); refcount_set(&io->count, 1);
} }
return io; return io;
} }
void ext4_put_io_end_defer(ext4_io_end_t *io_end) void ext4_put_io_end_defer(ext4_io_end_t *io_end)
{ {
if (atomic_dec_and_test(&io_end->count)) { if (refcount_dec_and_test(&io_end->count)) {
if (!(io_end->flag & EXT4_IO_END_UNWRITTEN) || !io_end->size) { if (!(io_end->flag & EXT4_IO_END_UNWRITTEN) || !io_end->size) {
ext4_release_io_end(io_end); ext4_release_io_end(io_end);
return; return;
...@@ -276,7 +276,7 @@ int ext4_put_io_end(ext4_io_end_t *io_end) ...@@ -276,7 +276,7 @@ int ext4_put_io_end(ext4_io_end_t *io_end)
{ {
int err = 0; int err = 0;
if (atomic_dec_and_test(&io_end->count)) { if (refcount_dec_and_test(&io_end->count)) {
if (io_end->flag & EXT4_IO_END_UNWRITTEN) { if (io_end->flag & EXT4_IO_END_UNWRITTEN) {
err = ext4_convert_unwritten_extents(io_end->handle, err = ext4_convert_unwritten_extents(io_end->handle,
io_end->inode, io_end->offset, io_end->inode, io_end->offset,
...@@ -291,7 +291,7 @@ int ext4_put_io_end(ext4_io_end_t *io_end) ...@@ -291,7 +291,7 @@ int ext4_put_io_end(ext4_io_end_t *io_end)
ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end) ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end)
{ {
atomic_inc(&io_end->count); refcount_inc(&io_end->count);
return io_end; return io_end;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册