Skip to content

Commit a51bf59

Browse files
jhovoldgregkh
authored andcommitted
firmware: arm_scmi: quirk: Prevent writes to string constants
commit 572ce54 upstream. The quirk version range is typically a string constant and must not be modified (e.g. as it may be stored in read-only memory). Attempting to do so can trigger faults such as: | Unable to handle kernel write to read-only memory at virtual | address ffffc036d998a947 Update the range parsing so that it operates on a copy of the version range string, and mark all the quirk strings as const to reduce the risk of introducing similar future issues. Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220437 Fixes: 487c407 ("firmware: arm_scmi: Add common framework to handle firmware quirks") Cc: [email protected] # 6.16 Cc: Cristian Marussi <[email protected]> Reported-by: Jan Palus <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Message-Id: <[email protected]> [sudeep.holla: minor commit message rewording; switch to cleanup helpers] Signed-off-by: Sudeep Holla <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a1202b7 commit a51bf59

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

drivers/firmware/arm_scmi/quirks.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
*/
7272

7373
#include <linux/ctype.h>
74+
#include <linux/cleanup.h>
7475
#include <linux/device.h>
7576
#include <linux/export.h>
7677
#include <linux/hashtable.h>
@@ -89,9 +90,9 @@
8990
struct scmi_quirk {
9091
bool enabled;
9192
const char *name;
92-
char *vendor;
93-
char *sub_vendor_id;
94-
char *impl_ver_range;
93+
const char *vendor;
94+
const char *sub_vendor_id;
95+
const char *impl_ver_range;
9596
u32 start_range;
9697
u32 end_range;
9798
struct static_key_false *key;
@@ -217,7 +218,7 @@ static unsigned int scmi_quirk_signature(const char *vend, const char *sub_vend)
217218

218219
static int scmi_quirk_range_parse(struct scmi_quirk *quirk)
219220
{
220-
const char *last, *first = quirk->impl_ver_range;
221+
const char *last, *first __free(kfree) = NULL;
221222
size_t len;
222223
char *sep;
223224
int ret;
@@ -228,8 +229,12 @@ static int scmi_quirk_range_parse(struct scmi_quirk *quirk)
228229
if (!len)
229230
return 0;
230231

232+
first = kmemdup(quirk->impl_ver_range, len + 1, GFP_KERNEL);
233+
if (!first)
234+
return -ENOMEM;
235+
231236
last = first + len - 1;
232-
sep = strchr(quirk->impl_ver_range, '-');
237+
sep = strchr(first, '-');
233238
if (sep)
234239
*sep = '\0';
235240

0 commit comments

Comments
 (0)