Skip to content

Commit 764cedc

Browse files
keesrafaeljw
authored andcommitted
thermal: int340x: Use struct_group() for memcpy() region
In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), avoid intentionally writing across neighboring fields. Use struct_group() in struct art around members weight, and ac[0-9]_max, so they can be referenced together. This will allow memcpy() and sizeof() to more easily reason about sizes, improve readability, and avoid future warnings about writing beyond the end of weight. "pahole" shows no size nor member offset changes to struct art. "objdump -d" shows no meaningful object code changes (i.e. only source line number induced differences). Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1360572 commit 764cedc

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ static int fill_art(char __user *ubuf)
250250
get_single_name(arts[i].source, art_user[i].source_device);
251251
get_single_name(arts[i].target, art_user[i].target_device);
252252
/* copy the rest int data in addition to source and target */
253-
memcpy(&art_user[i].weight, &arts[i].weight,
254-
sizeof(u64) * (ACPI_NR_ART_ELEMENTS - 2));
253+
BUILD_BUG_ON(sizeof(art_user[i].data) !=
254+
sizeof(u64) * (ACPI_NR_ART_ELEMENTS - 2));
255+
memcpy(&art_user[i].data, &arts[i].data, sizeof(art_user[i].data));
255256
}
256257

257258
if (copy_to_user(ubuf, art_user, art_len))

drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.h

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717
struct art {
1818
acpi_handle source;
1919
acpi_handle target;
20-
u64 weight;
21-
u64 ac0_max;
22-
u64 ac1_max;
23-
u64 ac2_max;
24-
u64 ac3_max;
25-
u64 ac4_max;
26-
u64 ac5_max;
27-
u64 ac6_max;
28-
u64 ac7_max;
29-
u64 ac8_max;
30-
u64 ac9_max;
20+
struct_group(data,
21+
u64 weight;
22+
u64 ac0_max;
23+
u64 ac1_max;
24+
u64 ac2_max;
25+
u64 ac3_max;
26+
u64 ac4_max;
27+
u64 ac5_max;
28+
u64 ac6_max;
29+
u64 ac7_max;
30+
u64 ac8_max;
31+
u64 ac9_max;
32+
);
3133
} __packed;
3234

3335
struct trt {
@@ -47,17 +49,19 @@ union art_object {
4749
struct {
4850
char source_device[8]; /* ACPI single name */
4951
char target_device[8]; /* ACPI single name */
50-
u64 weight;
51-
u64 ac0_max_level;
52-
u64 ac1_max_level;
53-
u64 ac2_max_level;
54-
u64 ac3_max_level;
55-
u64 ac4_max_level;
56-
u64 ac5_max_level;
57-
u64 ac6_max_level;
58-
u64 ac7_max_level;
59-
u64 ac8_max_level;
60-
u64 ac9_max_level;
52+
struct_group(data,
53+
u64 weight;
54+
u64 ac0_max_level;
55+
u64 ac1_max_level;
56+
u64 ac2_max_level;
57+
u64 ac3_max_level;
58+
u64 ac4_max_level;
59+
u64 ac5_max_level;
60+
u64 ac6_max_level;
61+
u64 ac7_max_level;
62+
u64 ac8_max_level;
63+
u64 ac9_max_level;
64+
);
6165
};
6266
u64 __data[ACPI_NR_ART_ELEMENTS];
6367
};

0 commit comments

Comments
 (0)