Skip to content

Commit e60c2bb

Browse files
committed
Merge: audit: backport kernel audit enhancements and fixes up to upstream v6.10
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4653 JIRA: https://issues.redhat.com/browse/RHEL-35421 Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=62377223 Backport selected trivial fixes, cleanups, and enhancements from upstream up to version 6.10. This will help make Audit functionality more stable, bring useful enhancements/fixes downstream, and ease future backports. Selected upstream commits: [cleanup] 97f576e audit: Annotate struct audit_chunk with __counted_by [bug fix] 03adc61 audit,io_uring: io_uring openat triggers audit reference count underflow [cleanup] 3104d0e audit: remove unnecessary assignment in audit_dupe_lsm_field() [cleanup] aa13b70 audit: use KMEM_CACHE() instead of kmem_cache_create() In addition, the upstream commit ea47ab1 ("putname(): IS_ERR_OR_NULL() is wrong here") was added to the list as a dependency. Ricardo Robaina (5): putname(): IS_ERR_OR_NULL() is wrong here audit: Annotate struct audit_chunk with __counted_by audit,io_uring: io_uring openat triggers audit reference count underflow audit: remove unnecessary assignment in audit_dupe_lsm_field() audit: use KMEM_CACHE() instead of kmem_cache_create() fs/namei.c | 11 ++++++----- include/linux/fs.h | 2 +- kernel/audit.c | 4 +--- kernel/audit_tree.c | 2 +- kernel/auditfilter.c | 2 +- kernel/auditsc.c | 8 ++++---- 6 files changed, 14 insertions(+), 15 deletions(-) Signed-off-by: Ricardo Robaina <rrobaina@redhat.com> Approved-by: Richard Guy Briggs <rgb@redhat.com> Approved-by: Ondrej Mosnáček <omosnacek@gmail.com> Approved-by: Wander Lairson Costa <wander@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 8e86720 + a4c4823 commit e60c2bb

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

fs/namei.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ getname_flags(const char __user *filename, int flags, int *empty)
187187
}
188188
}
189189

190-
result->refcnt = 1;
190+
atomic_set(&result->refcnt, 1);
191191
/* The empty path is special. */
192192
if (unlikely(!len)) {
193193
if (empty)
@@ -248,20 +248,21 @@ getname_kernel(const char * filename)
248248
memcpy((char *)result->name, filename, len);
249249
result->uptr = NULL;
250250
result->aname = NULL;
251-
result->refcnt = 1;
251+
atomic_set(&result->refcnt, 1);
252252
audit_getname(result);
253253

254254
return result;
255255
}
256256

257257
void putname(struct filename *name)
258258
{
259-
if (IS_ERR_OR_NULL(name))
259+
if (IS_ERR(name))
260260
return;
261261

262-
BUG_ON(name->refcnt <= 0);
262+
if (WARN_ON_ONCE(!atomic_read(&name->refcnt)))
263+
return;
263264

264-
if (--name->refcnt > 0)
265+
if (!atomic_dec_and_test(&name->refcnt))
265266
return;
266267

267268
if (name->name != name->iname) {

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,7 @@ struct audit_names;
27762776
struct filename {
27772777
const char *name; /* pointer to actual string */
27782778
const __user char *uptr; /* original userland pointer */
2779-
int refcnt;
2779+
atomic_t refcnt;
27802780
struct audit_names *aname;
27812781
const char iname[];
27822782
};

kernel/audit.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,9 +1676,7 @@ static int __init audit_init(void)
16761676
if (audit_initialized == AUDIT_DISABLED)
16771677
return 0;
16781678

1679-
audit_buffer_cache = kmem_cache_create("audit_buffer",
1680-
sizeof(struct audit_buffer),
1681-
0, SLAB_PANIC, NULL);
1679+
audit_buffer_cache = KMEM_CACHE(audit_buffer, SLAB_PANIC);
16821680

16831681
skb_queue_head_init(&audit_queue);
16841682
skb_queue_head_init(&audit_retry_queue);

kernel/audit_tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct audit_chunk {
3434
struct list_head list;
3535
struct audit_tree *owner;
3636
unsigned index; /* index; upper bit indicates 'will prune' */
37-
} owners[];
37+
} owners[] __counted_by(count);
3838
};
3939

4040
struct audit_tree_mark {

kernel/auditfilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
788788
static inline int audit_dupe_lsm_field(struct audit_field *df,
789789
struct audit_field *sf)
790790
{
791-
int ret = 0;
791+
int ret;
792792
char *lsm_str;
793793

794794
/* our own copy of lsm_str */

kernel/auditsc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,7 @@ __audit_reusename(const __user char *uptr)
22162216
if (!n->name)
22172217
continue;
22182218
if (n->name->uptr == uptr) {
2219-
n->name->refcnt++;
2219+
atomic_inc(&n->name->refcnt);
22202220
return n->name;
22212221
}
22222222
}
@@ -2245,7 +2245,7 @@ void __audit_getname(struct filename *name)
22452245
n->name = name;
22462246
n->name_len = AUDIT_NAME_FULL;
22472247
name->aname = n;
2248-
name->refcnt++;
2248+
atomic_inc(&name->refcnt);
22492249
}
22502250

22512251
static inline int audit_copy_fcaps(struct audit_names *name,
@@ -2377,7 +2377,7 @@ void __audit_inode(struct filename *name, const struct dentry *dentry,
23772377
return;
23782378
if (name) {
23792379
n->name = name;
2380-
name->refcnt++;
2380+
atomic_inc(&name->refcnt);
23812381
}
23822382

23832383
out:
@@ -2504,7 +2504,7 @@ void __audit_inode_child(struct inode *parent,
25042504
if (found_parent) {
25052505
found_child->name = found_parent->name;
25062506
found_child->name_len = AUDIT_NAME_FULL;
2507-
found_child->name->refcnt++;
2507+
atomic_inc(&found_child->name->refcnt);
25082508
}
25092509
}
25102510

0 commit comments

Comments
 (0)