Skip to content

Commit 9d9c1cf

Browse files
committed
Merge tag 'mm-nonmm-stable-2025-12-11-11-47' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull misc updates from Andrew Morton: "There are no significant series in this small merge. Please see the individual changelogs for details" [ Editor's note: it's mainly ocfs2 and a couple of random fixes ] * tag 'mm-nonmm-stable-2025-12-11-11-47' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: mm: memfd_luo: add CONFIG_SHMEM dependency mm: shmem: avoid build warning for CONFIG_SHMEM=n ocfs2: fix memory leak in ocfs2_merge_rec_left() ocfs2: invalidate inode if i_mode is zero after block read ocfs2: avoid -Wflex-array-member-not-at-end warning ocfs2: convert remaining read-only checks to ocfs2_emergency_state ocfs2: add ocfs2_emergency_state helper and apply to setattr checkpatch: add uninitialized pointer with __free attribute check args: fix documentation to reflect the correct numbers ocfs2: fix kernel BUG in ocfs2_find_victim_chain liveupdate: luo_core: fix redundant bound check in luo_ioctl() ocfs2: validate inline xattr size and entry count in ocfs2_xattr_ibody_list fs/fat: remove unnecessary wrapper fat_max_cache() ocfs2: replace deprecated strcpy with strscpy ocfs2: check tl_used after reading it from trancate log inode liveupdate: luo_file: don't use invalid list iterator
2 parents 2516a87 + 601cc39 commit 9d9c1cf

22 files changed

Lines changed: 154 additions & 44 deletions

File tree

Documentation/dev-tools/checkpatch.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,29 @@ Functions and Variables
10021002

10031003
return bar;
10041004

1005+
**UNINITIALIZED_PTR_WITH_FREE**
1006+
Pointers with __free attribute should be declared at the place of use
1007+
and initialized (see include/linux/cleanup.h). In this case
1008+
declarations at the top of the function rule can be relaxed. Not doing
1009+
so may lead to undefined behavior as the memory assigned (garbage,
1010+
in case not initialized) to the pointer is freed automatically when
1011+
the pointer goes out of scope.
1012+
1013+
Also see: https://lore.kernel.org/lkml/58fd478f408a34b578ee8d949c5c4b4da4d4f41d.camel@HansenPartnership.com/
1014+
1015+
Example::
1016+
1017+
type var __free(free_func);
1018+
... // var not used, but, in future someone might add a return here
1019+
var = malloc(var_size);
1020+
...
1021+
1022+
should be initialized as::
1023+
1024+
...
1025+
type var __free(free_func) = malloc(var_size);
1026+
...
1027+
10051028

10061029
Permissions
10071030
-----------

fs/fat/cache.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ struct fat_cache_id {
2929
int dcluster;
3030
};
3131

32-
static inline int fat_max_cache(struct inode *inode)
33-
{
34-
return FAT_MAX_CACHE;
35-
}
36-
3732
static struct kmem_cache *fat_cache_cachep;
3833

3934
static void init_once(void *foo)
@@ -145,7 +140,7 @@ static void fat_cache_add(struct inode *inode, struct fat_cache_id *new)
145140

146141
cache = fat_cache_merge(inode, new);
147142
if (cache == NULL) {
148-
if (MSDOS_I(inode)->nr_caches < fat_max_cache(inode)) {
143+
if (MSDOS_I(inode)->nr_caches < FAT_MAX_CACHE) {
149144
MSDOS_I(inode)->nr_caches++;
150145
spin_unlock(&MSDOS_I(inode)->cache_lru_lock);
151146

fs/ocfs2/alloc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/fs.h>
1111
#include <linux/types.h>
1212
#include <linux/slab.h>
13+
#include <linux/string.h>
1314
#include <linux/highmem.h>
1415
#include <linux/swap.h>
1516
#include <linux/quotaops.h>
@@ -1037,7 +1038,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
10371038
memset(bhs[i]->b_data, 0, osb->sb->s_blocksize);
10381039
eb = (struct ocfs2_extent_block *) bhs[i]->b_data;
10391040
/* Ok, setup the minimal stuff here. */
1040-
strcpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
1041+
strscpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
10411042
eb->h_blkno = cpu_to_le64(first_blkno);
10421043
eb->h_fs_generation = cpu_to_le32(osb->fs_generation);
10431044
eb->h_suballoc_slot =
@@ -3654,7 +3655,6 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path,
36543655
* So we use the new rightmost path.
36553656
*/
36563657
ocfs2_mv_path(right_path, left_path);
3657-
left_path = NULL;
36583658
} else
36593659
ocfs2_complete_edge_insert(handle, left_path,
36603660
right_path, subtree_index);
@@ -6164,7 +6164,7 @@ static int ocfs2_get_truncate_log_info(struct ocfs2_super *osb,
61646164
struct buffer_head *bh = NULL;
61656165
struct ocfs2_dinode *di;
61666166
struct ocfs2_truncate_log *tl;
6167-
unsigned int tl_count;
6167+
unsigned int tl_count, tl_used;
61686168

61696169
inode = ocfs2_get_system_file_inode(osb,
61706170
TRUNCATE_LOG_SYSTEM_INODE,
@@ -6185,8 +6185,10 @@ static int ocfs2_get_truncate_log_info(struct ocfs2_super *osb,
61856185
di = (struct ocfs2_dinode *)bh->b_data;
61866186
tl = &di->id2.i_dealloc;
61876187
tl_count = le16_to_cpu(tl->tl_count);
6188+
tl_used = le16_to_cpu(tl->tl_used);
61886189
if (unlikely(tl_count > ocfs2_truncate_recs_per_inode(osb->sb) ||
6189-
tl_count == 0)) {
6190+
tl_count == 0 ||
6191+
tl_used > tl_count)) {
61906192
status = -EFSCORRUPTED;
61916193
iput(inode);
61926194
brelse(bh);
@@ -6744,7 +6746,7 @@ static int ocfs2_reuse_blk_from_dealloc(handle_t *handle,
67446746
/* We can't guarantee that buffer head is still cached, so
67456747
* polutlate the extent block again.
67466748
*/
6747-
strcpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
6749+
strscpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
67486750
eb->h_blkno = cpu_to_le64(bf->free_blk);
67496751
eb->h_fs_generation = cpu_to_le32(osb->fs_generation);
67506752
eb->h_suballoc_slot = cpu_to_le16(real_slot);

fs/ocfs2/buffer_head_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
434434
BUG_ON(buffer_jbd(bh));
435435
ocfs2_check_super_or_backup(osb->sb, bh->b_blocknr);
436436

437-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb)) {
437+
if (unlikely(ocfs2_emergency_state(osb))) {
438438
ret = -EROFS;
439439
mlog_errno(ret);
440440
goto out;

fs/ocfs2/cluster/nodemanager.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/slab.h>
7+
#include <linux/string.h>
78
#include <linux/kernel.h>
89
#include <linux/module.h>
910
#include <linux/configfs.h>
@@ -590,7 +591,7 @@ static struct config_item *o2nm_node_group_make_item(struct config_group *group,
590591
if (node == NULL)
591592
return ERR_PTR(-ENOMEM);
592593

593-
strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */
594+
strscpy(node->nd_name, name); /* use item.ci_namebuf instead? */
594595
config_item_init_type_name(&node->nd_item, name, &o2nm_node_type);
595596
spin_lock_init(&node->nd_lock);
596597

fs/ocfs2/dir.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void ocfs2_init_dir_trailer(struct inode *inode,
136136
struct ocfs2_dir_block_trailer *trailer;
137137

138138
trailer = ocfs2_trailer_from_bh(bh, inode->i_sb);
139-
strcpy(trailer->db_signature, OCFS2_DIR_TRAILER_SIGNATURE);
139+
strscpy(trailer->db_signature, OCFS2_DIR_TRAILER_SIGNATURE);
140140
trailer->db_compat_rec_len =
141141
cpu_to_le16(sizeof(struct ocfs2_dir_block_trailer));
142142
trailer->db_parent_dinode = cpu_to_le64(OCFS2_I(inode)->ip_blkno);
@@ -2213,14 +2213,14 @@ static struct ocfs2_dir_entry *ocfs2_fill_initial_dirents(struct inode *inode,
22132213
de->name_len = 1;
22142214
de->rec_len =
22152215
cpu_to_le16(OCFS2_DIR_REC_LEN(de->name_len));
2216-
strcpy(de->name, ".");
2216+
strscpy(de->name, ".");
22172217
ocfs2_set_de_type(de, S_IFDIR);
22182218

22192219
de = (struct ocfs2_dir_entry *) ((char *)de + le16_to_cpu(de->rec_len));
22202220
de->inode = cpu_to_le64(OCFS2_I(parent)->ip_blkno);
22212221
de->rec_len = cpu_to_le16(size - OCFS2_DIR_REC_LEN(1));
22222222
de->name_len = 2;
2223-
strcpy(de->name, "..");
2223+
strscpy(de->name, "..");
22242224
ocfs2_set_de_type(de, S_IFDIR);
22252225

22262226
return de;
@@ -2378,7 +2378,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
23782378

23792379
dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data;
23802380
memset(dx_root, 0, osb->sb->s_blocksize);
2381-
strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
2381+
strscpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
23822382
dx_root->dr_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
23832383
dx_root->dr_suballoc_loc = cpu_to_le64(suballoc_loc);
23842384
dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit);
@@ -2454,7 +2454,7 @@ static int ocfs2_dx_dir_format_cluster(struct ocfs2_super *osb,
24542454
dx_leaf = (struct ocfs2_dx_leaf *) bh->b_data;
24552455

24562456
memset(dx_leaf, 0, osb->sb->s_blocksize);
2457-
strcpy(dx_leaf->dl_signature, OCFS2_DX_LEAF_SIGNATURE);
2457+
strscpy(dx_leaf->dl_signature, OCFS2_DX_LEAF_SIGNATURE);
24582458
dx_leaf->dl_fs_generation = cpu_to_le32(osb->fs_generation);
24592459
dx_leaf->dl_blkno = cpu_to_le64(bh->b_blocknr);
24602460
dx_leaf->dl_list.de_count =

fs/ocfs2/file.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,
179179
file->f_path.dentry->d_name.name,
180180
(unsigned long long)datasync);
181181

182-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
182+
if (unlikely(ocfs2_emergency_state(osb)))
183183
return -EROFS;
184184

185185
err = file_write_and_wait_range(file, start, end);
@@ -209,7 +209,7 @@ int ocfs2_should_update_atime(struct inode *inode,
209209
struct timespec64 now;
210210
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
211211

212-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
212+
if (unlikely(ocfs2_emergency_state(osb)))
213213
return 0;
214214

215215
if ((inode->i_flags & S_NOATIME) ||
@@ -1136,6 +1136,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
11361136
attr->ia_valid & ATTR_GID ?
11371137
from_kgid(&init_user_ns, attr->ia_gid) : 0);
11381138

1139+
status = ocfs2_emergency_state(osb);
1140+
if (unlikely(status)) {
1141+
mlog_errno(status);
1142+
goto bail;
1143+
}
1144+
11391145
/* ensuring we don't even attempt to truncate a symlink */
11401146
if (S_ISLNK(inode->i_mode))
11411147
attr->ia_valid &= ~ATTR_SIZE;
@@ -1943,7 +1949,7 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
19431949
handle_t *handle;
19441950
unsigned long long max_off = inode->i_sb->s_maxbytes;
19451951

1946-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
1952+
if (unlikely(ocfs2_emergency_state(osb)))
19471953
return -EROFS;
19481954

19491955
inode_lock(inode);
@@ -2707,7 +2713,7 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in,
27072713
return -EINVAL;
27082714
if (!ocfs2_refcount_tree(osb))
27092715
return -EOPNOTSUPP;
2710-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
2716+
if (unlikely(ocfs2_emergency_state(osb)))
27112717
return -EROFS;
27122718

27132719
/* Lock both files against IO */

fs/ocfs2/inode.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,14 @@ int ocfs2_validate_inode_block(struct super_block *sb,
14421442
goto bail;
14431443
}
14441444

1445+
if ((!di->i_links_count && !di->i_links_count_hi) || !di->i_mode) {
1446+
mlog(ML_ERROR, "Invalid dinode #%llu: "
1447+
"Corrupt state (nlink = %u or mode = %u) detected!\n",
1448+
(unsigned long long)bh->b_blocknr,
1449+
ocfs2_read_links_count(di), le16_to_cpu(di->i_mode));
1450+
rc = -EFSCORRUPTED;
1451+
goto bail;
1452+
}
14451453
/*
14461454
* Errors after here are fatal.
14471455
*/
@@ -1604,8 +1612,7 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb,
16041612
trace_ocfs2_filecheck_repair_inode_block(
16051613
(unsigned long long)bh->b_blocknr);
16061614

1607-
if (ocfs2_is_hard_readonly(OCFS2_SB(sb)) ||
1608-
ocfs2_is_soft_readonly(OCFS2_SB(sb))) {
1615+
if (unlikely(ocfs2_emergency_state(OCFS2_SB(sb)))) {
16091616
mlog(ML_ERROR,
16101617
"Filecheck: cannot repair dinode #%llu "
16111618
"on readonly filesystem\n",

fs/ocfs2/move_extents.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context)
909909
struct buffer_head *di_bh = NULL;
910910
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
911911

912-
if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
912+
if (unlikely(ocfs2_emergency_state(osb)))
913913
return -EROFS;
914914

915915
inode_lock(inode);

fs/ocfs2/namei.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/fs.h>
2424
#include <linux/types.h>
2525
#include <linux/slab.h>
26+
#include <linux/string.h>
2627
#include <linux/highmem.h>
2728
#include <linux/quotaops.h>
2829
#include <linux/iversion.h>
@@ -568,7 +569,7 @@ static int __ocfs2_mknod_locked(struct inode *dir,
568569
ocfs2_set_links_count(fe, inode->i_nlink);
569570

570571
fe->i_last_eb_blk = 0;
571-
strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
572+
strscpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
572573
fe->i_flags |= cpu_to_le32(OCFS2_VALID_FL);
573574
ktime_get_coarse_real_ts64(&ts);
574575
fe->i_atime = fe->i_ctime = fe->i_mtime =

0 commit comments

Comments
 (0)