Skip to content

Commit 7255a39

Browse files
committed
Merge tag 'x86_urgent_for_v5.10-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Borislav Petkov: "A couple of urgent fixes which accumulated this last week: - Two resctrl fixes to prevent refcount leaks when manipulating the resctrl fs (Xiaochen Shen) - Correct prctl(PR_GET_SPECULATION_CTRL) reporting (Anand K Mistry) - A fix to not lose already seen MCE severity which determines whether the machine can recover (Gabriele Paoloni)" * tag 'x86_urgent_for_v5.10-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mce: Do not overwrite no_way_out if mce_end() fails x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb x86/resctrl: Add necessary kernfs_put() calls to prevent refcount leak x86/resctrl: Remove superfluous kernfs_get() calls to prevent refcount leak
2 parents aae5ab8 + 25bc65d commit 7255a39

File tree

3 files changed

+32
-43
lines changed

3 files changed

+32
-43
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,13 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
739739
if (boot_cpu_has(X86_FEATURE_IBPB)) {
740740
setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
741741

742+
spectre_v2_user_ibpb = mode;
742743
switch (cmd) {
743744
case SPECTRE_V2_USER_CMD_FORCE:
744745
case SPECTRE_V2_USER_CMD_PRCTL_IBPB:
745746
case SPECTRE_V2_USER_CMD_SECCOMP_IBPB:
746747
static_branch_enable(&switch_mm_always_ibpb);
748+
spectre_v2_user_ibpb = SPECTRE_V2_USER_STRICT;
747749
break;
748750
case SPECTRE_V2_USER_CMD_PRCTL:
749751
case SPECTRE_V2_USER_CMD_AUTO:
@@ -757,8 +759,6 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
757759
pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n",
758760
static_key_enabled(&switch_mm_always_ibpb) ?
759761
"always-on" : "conditional");
760-
761-
spectre_v2_user_ibpb = mode;
762762
}
763763

764764
/*

arch/x86/kernel/cpu/mce/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,10 @@ noinstr void do_machine_check(struct pt_regs *regs)
13841384
* When there's any problem use only local no_way_out state.
13851385
*/
13861386
if (!lmce) {
1387-
if (mce_end(order) < 0)
1388-
no_way_out = worst >= MCE_PANIC_SEVERITY;
1387+
if (mce_end(order) < 0) {
1388+
if (!no_way_out)
1389+
no_way_out = worst >= MCE_PANIC_SEVERITY;
1390+
}
13891391
} else {
13901392
/*
13911393
* If there was a fatal machine check we should have

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,24 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
507507
return ret ?: nbytes;
508508
}
509509

510+
/**
511+
* rdtgroup_remove - the helper to remove resource group safely
512+
* @rdtgrp: resource group to remove
513+
*
514+
* On resource group creation via a mkdir, an extra kernfs_node reference is
515+
* taken to ensure that the rdtgroup structure remains accessible for the
516+
* rdtgroup_kn_unlock() calls where it is removed.
517+
*
518+
* Drop the extra reference here, then free the rdtgroup structure.
519+
*
520+
* Return: void
521+
*/
522+
static void rdtgroup_remove(struct rdtgroup *rdtgrp)
523+
{
524+
kernfs_put(rdtgrp->kn);
525+
kfree(rdtgrp);
526+
}
527+
510528
struct task_move_callback {
511529
struct callback_head work;
512530
struct rdtgroup *rdtgrp;
@@ -529,7 +547,7 @@ static void move_myself(struct callback_head *head)
529547
(rdtgrp->flags & RDT_DELETED)) {
530548
current->closid = 0;
531549
current->rmid = 0;
532-
kfree(rdtgrp);
550+
rdtgroup_remove(rdtgrp);
533551
}
534552

535553
if (unlikely(current->flags & PF_EXITING))
@@ -1769,7 +1787,6 @@ static int rdtgroup_mkdir_info_resdir(struct rdt_resource *r, char *name,
17691787
if (IS_ERR(kn_subdir))
17701788
return PTR_ERR(kn_subdir);
17711789

1772-
kernfs_get(kn_subdir);
17731790
ret = rdtgroup_kn_set_ugid(kn_subdir);
17741791
if (ret)
17751792
return ret;
@@ -1792,7 +1809,6 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
17921809
kn_info = kernfs_create_dir(parent_kn, "info", parent_kn->mode, NULL);
17931810
if (IS_ERR(kn_info))
17941811
return PTR_ERR(kn_info);
1795-
kernfs_get(kn_info);
17961812

17971813
ret = rdtgroup_add_files(kn_info, RF_TOP_INFO);
17981814
if (ret)
@@ -1813,12 +1829,6 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
18131829
goto out_destroy;
18141830
}
18151831

1816-
/*
1817-
* This extra ref will be put in kernfs_remove() and guarantees
1818-
* that @rdtgrp->kn is always accessible.
1819-
*/
1820-
kernfs_get(kn_info);
1821-
18221832
ret = rdtgroup_kn_set_ugid(kn_info);
18231833
if (ret)
18241834
goto out_destroy;
@@ -1847,12 +1857,6 @@ mongroup_create_dir(struct kernfs_node *parent_kn, struct rdtgroup *prgrp,
18471857
if (dest_kn)
18481858
*dest_kn = kn;
18491859

1850-
/*
1851-
* This extra ref will be put in kernfs_remove() and guarantees
1852-
* that @rdtgrp->kn is always accessible.
1853-
*/
1854-
kernfs_get(kn);
1855-
18561860
ret = rdtgroup_kn_set_ugid(kn);
18571861
if (ret)
18581862
goto out_destroy;
@@ -2079,8 +2083,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
20792083
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
20802084
rdtgroup_pseudo_lock_remove(rdtgrp);
20812085
kernfs_unbreak_active_protection(kn);
2082-
kernfs_put(rdtgrp->kn);
2083-
kfree(rdtgrp);
2086+
rdtgroup_remove(rdtgrp);
20842087
} else {
20852088
kernfs_unbreak_active_protection(kn);
20862089
}
@@ -2139,13 +2142,11 @@ static int rdt_get_tree(struct fs_context *fc)
21392142
&kn_mongrp);
21402143
if (ret < 0)
21412144
goto out_info;
2142-
kernfs_get(kn_mongrp);
21432145

21442146
ret = mkdir_mondata_all(rdtgroup_default.kn,
21452147
&rdtgroup_default, &kn_mondata);
21462148
if (ret < 0)
21472149
goto out_mongrp;
2148-
kernfs_get(kn_mondata);
21492150
rdtgroup_default.mon.mon_data_kn = kn_mondata;
21502151
}
21512152

@@ -2357,7 +2358,7 @@ static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp)
23572358
if (atomic_read(&sentry->waitcount) != 0)
23582359
sentry->flags = RDT_DELETED;
23592360
else
2360-
kfree(sentry);
2361+
rdtgroup_remove(sentry);
23612362
}
23622363
}
23632364

@@ -2399,7 +2400,7 @@ static void rmdir_all_sub(void)
23992400
if (atomic_read(&rdtgrp->waitcount) != 0)
24002401
rdtgrp->flags = RDT_DELETED;
24012402
else
2402-
kfree(rdtgrp);
2403+
rdtgroup_remove(rdtgrp);
24032404
}
24042405
/* Notify online CPUs to update per cpu storage and PQR_ASSOC MSR */
24052406
update_closid_rmid(cpu_online_mask, &rdtgroup_default);
@@ -2499,11 +2500,6 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
24992500
if (IS_ERR(kn))
25002501
return PTR_ERR(kn);
25012502

2502-
/*
2503-
* This extra ref will be put in kernfs_remove() and guarantees
2504-
* that kn is always accessible.
2505-
*/
2506-
kernfs_get(kn);
25072503
ret = rdtgroup_kn_set_ugid(kn);
25082504
if (ret)
25092505
goto out_destroy;
@@ -2838,8 +2834,8 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
28382834
/*
28392835
* kernfs_remove() will drop the reference count on "kn" which
28402836
* will free it. But we still need it to stick around for the
2841-
* rdtgroup_kn_unlock(kn} call below. Take one extra reference
2842-
* here, which will be dropped inside rdtgroup_kn_unlock().
2837+
* rdtgroup_kn_unlock(kn) call. Take one extra reference here,
2838+
* which will be dropped by kernfs_put() in rdtgroup_remove().
28432839
*/
28442840
kernfs_get(kn);
28452841

@@ -2880,6 +2876,7 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
28802876
out_idfree:
28812877
free_rmid(rdtgrp->mon.rmid);
28822878
out_destroy:
2879+
kernfs_put(rdtgrp->kn);
28832880
kernfs_remove(rdtgrp->kn);
28842881
out_free_rgrp:
28852882
kfree(rdtgrp);
@@ -2892,7 +2889,7 @@ static void mkdir_rdt_prepare_clean(struct rdtgroup *rgrp)
28922889
{
28932890
kernfs_remove(rgrp->kn);
28942891
free_rmid(rgrp->mon.rmid);
2895-
kfree(rgrp);
2892+
rdtgroup_remove(rgrp);
28962893
}
28972894

28982895
/*
@@ -3049,11 +3046,6 @@ static int rdtgroup_rmdir_mon(struct kernfs_node *kn, struct rdtgroup *rdtgrp,
30493046
WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list));
30503047
list_del(&rdtgrp->mon.crdtgrp_list);
30513048

3052-
/*
3053-
* one extra hold on this, will drop when we kfree(rdtgrp)
3054-
* in rdtgroup_kn_unlock()
3055-
*/
3056-
kernfs_get(kn);
30573049
kernfs_remove(rdtgrp->kn);
30583050

30593051
return 0;
@@ -3065,11 +3057,6 @@ static int rdtgroup_ctrl_remove(struct kernfs_node *kn,
30653057
rdtgrp->flags = RDT_DELETED;
30663058
list_del(&rdtgrp->rdtgroup_list);
30673059

3068-
/*
3069-
* one extra hold on this, will drop when we kfree(rdtgrp)
3070-
* in rdtgroup_kn_unlock()
3071-
*/
3072-
kernfs_get(kn);
30733060
kernfs_remove(rdtgrp->kn);
30743061
return 0;
30753062
}

0 commit comments

Comments
 (0)