Skip to content

Commit 4f0f586

Browse files
samitolvanenkees
authored andcommitted
treewide: Change list_sort to use const pointers
list_sort() internally casts the comparison function passed to it to a different type with constant struct list_head pointers, and uses this pointer to call the functions, which trips indirect call Control-Flow Integrity (CFI) checking. Instead of removing the consts, this change defines the list_cmp_func_t type and changes the comparison function types of all list_sort() callers to use const pointers, thus avoiding type mismatches. Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20210408182843.1754385-10-samitolvanen@google.com
1 parent 9f5b400 commit 4f0f586

41 files changed

Lines changed: 90 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,8 +2190,8 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,
21902190
return offset;
21912191
}
21922192

2193-
static int vgic_its_ite_cmp(void *priv, struct list_head *a,
2194-
struct list_head *b)
2193+
static int vgic_its_ite_cmp(void *priv, const struct list_head *a,
2194+
const struct list_head *b)
21952195
{
21962196
struct its_ite *itea = container_of(a, struct its_ite, ite_list);
21972197
struct its_ite *iteb = container_of(b, struct its_ite, ite_list);
@@ -2329,8 +2329,8 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,
23292329
return offset;
23302330
}
23312331

2332-
static int vgic_its_device_cmp(void *priv, struct list_head *a,
2333-
struct list_head *b)
2332+
static int vgic_its_device_cmp(void *priv, const struct list_head *a,
2333+
const struct list_head *b)
23342334
{
23352335
struct its_device *deva = container_of(a, struct its_device, dev_list);
23362336
struct its_device *devb = container_of(b, struct its_device, dev_list);

arch/arm64/kvm/vgic/vgic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ static struct kvm_vcpu *vgic_target_oracle(struct vgic_irq *irq)
255255
* Return negative if "a" sorts before "b", 0 to preserve order, and positive
256256
* to sort "b" before "a".
257257
*/
258-
static int vgic_irq_cmp(void *priv, struct list_head *a, struct list_head *b)
258+
static int vgic_irq_cmp(void *priv, const struct list_head *a,
259+
const struct list_head *b)
259260
{
260261
struct vgic_irq *irqa = container_of(a, struct vgic_irq, ap_list);
261262
struct vgic_irq *irqb = container_of(b, struct vgic_irq, ap_list);

block/blk-mq-sched.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
7575
blk_mq_run_hw_queue(hctx, true);
7676
}
7777

78-
static int sched_rq_cmp(void *priv, struct list_head *a, struct list_head *b)
78+
static int sched_rq_cmp(void *priv, const struct list_head *a,
79+
const struct list_head *b)
7980
{
8081
struct request *rqa = container_of(a, struct request, queuelist);
8182
struct request *rqb = container_of(b, struct request, queuelist);

block/blk-mq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,8 @@ void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
18951895
spin_unlock(&ctx->lock);
18961896
}
18971897

1898-
static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b)
1898+
static int plug_rq_cmp(void *priv, const struct list_head *a,
1899+
const struct list_head *b)
18991900
{
19001901
struct request *rqa = container_of(a, struct request, queuelist);
19011902
struct request *rqb = container_of(b, struct request, queuelist);

drivers/acpi/nfit/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,8 @@ static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc,
11951195
return 0;
11961196
}
11971197

1198-
static int nfit_mem_cmp(void *priv, struct list_head *_a, struct list_head *_b)
1198+
static int nfit_mem_cmp(void *priv, const struct list_head *_a,
1199+
const struct list_head *_b)
11991200
{
12001201
struct nfit_mem *a = container_of(_a, typeof(*a), list);
12011202
struct nfit_mem *b = container_of(_b, typeof(*b), list);

drivers/acpi/numa/hmat.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ static bool hmat_update_best(u8 type, u32 value, u32 *best)
558558
return updated;
559559
}
560560

561-
static int initiator_cmp(void *priv, struct list_head *a, struct list_head *b)
561+
static int initiator_cmp(void *priv, const struct list_head *a,
562+
const struct list_head *b)
562563
{
563564
struct memory_initiator *ia;
564565
struct memory_initiator *ib;

drivers/clk/keystone/sci-clk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
503503

504504
#else
505505

506-
static int _cmp_sci_clk_list(void *priv, struct list_head *a,
507-
struct list_head *b)
506+
static int _cmp_sci_clk_list(void *priv, const struct list_head *a,
507+
const struct list_head *b)
508508
{
509509
struct sci_clk *ca = container_of(a, struct sci_clk, node);
510510
struct sci_clk *cb = container_of(b, struct sci_clk, node);

drivers/gpu/drm/drm_modes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ EXPORT_SYMBOL(drm_mode_prune_invalid);
12901290
* Negative if @lh_a is better than @lh_b, zero if they're equivalent, or
12911291
* positive if @lh_b is better than @lh_a.
12921292
*/
1293-
static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b)
1293+
static int drm_mode_compare(void *priv, const struct list_head *lh_a,
1294+
const struct list_head *lh_b)
12941295
{
12951296
struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head);
12961297
struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head);

drivers/gpu/drm/i915/gt/intel_engine_user.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static const u8 uabi_classes[] = {
4949
[VIDEO_ENHANCEMENT_CLASS] = I915_ENGINE_CLASS_VIDEO_ENHANCE,
5050
};
5151

52-
static int engine_cmp(void *priv, struct list_head *A, struct list_head *B)
52+
static int engine_cmp(void *priv, const struct list_head *A,
53+
const struct list_head *B)
5354
{
5455
const struct intel_engine_cs *a =
5556
container_of((struct rb_node *)A, typeof(*a), uabi_node);

drivers/gpu/drm/i915/gvt/debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct diff_mmio {
4141

4242
/* Compare two diff_mmio items. */
4343
static int mmio_offset_compare(void *priv,
44-
struct list_head *a, struct list_head *b)
44+
const struct list_head *a, const struct list_head *b)
4545
{
4646
struct diff_mmio *ma;
4747
struct diff_mmio *mb;

0 commit comments

Comments
 (0)