Remove VLA usage in rtc-s5m
Subsystems (4)
cover Remove VLA usage in rtc-s5m
This patchset aims to remove VLA usage from rtc-s5m.
The first patch moves an enum from rtc.h to rtc-s5m.c, as this is the only driver in which such enum is actually being used [1].
The second patch adds the enum name RTC_MAX_NUM_TIME_REGS, which will be used as a maximum length to the current VLAs, hence turning them into fixed-length arrays instead.
[1] https://marc.info/?l=linux-rtc&m=152060068925948&w=2
Thanks
Gustavo A. R. Silva (2):
rtc: s5m: move enum from rtc.h to rtc-s5m.c
rtc: s5m: Remove VLA usage
drivers/rtc/rtc-s5m.c | 25 +++++++++++++++++++------ include/linux/mfd/samsung/rtc.h | 11 ----------- 2 files changed, 19 insertions(+), 17 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 rtc: s5m: Move enum from rtc.h to rtc-s5m.c
Move this enum to rtc-s5m.c once it is meaningless to others drivers [1].
[1] https://marc.info/?l=linux-rtc&m=152060068925948&w=2
--- drivers/rtc/rtc-s5m.c | 11 +++++++++++ include/linux/mfd/samsung/rtc.h | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/rtc/rtc-s5m.c +11 -0
@@ -38,6 +38,17 @@*/ #define UDR_READ_RETRY_CNT 5 +enum { +RTC_SEC =0 , +RTC_MIN , +RTC_HOUR , +RTC_WEEKDAY , +RTC_DATE , +RTC_MONTH , +RTC_YEAR1 , +RTC_YEAR2 , +}; +/* * Registers used by the driver which are different between chipsets. *
include/linux/mfd/samsung/rtc.h +0 -11
@@ -141,15 +141,4 @@ enum s2mps_rtc_reg {#define WTSR_ENABLE_SHIFT 6#define WTSR_ENABLE_MASK (1 << WTSR_ENABLE_SHIFT) -enum { -RTC_SEC =0 , -RTC_MIN , -RTC_HOUR , -RTC_WEEKDAY , -RTC_DATE , -RTC_MONTH , -RTC_YEAR1 , -RTC_YEAR2 , -}; -#endif /* __LINUX_MFD_SEC_RTC_H */
Signature · 1 line
2.7.4
Re: [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
Quoted 3 lines · Gustavo A. R. Silva
Move this enum to
rtc-s5m.conce it is meaningless to others drivers [1].
Instead of external link (which might or might not work soon) you can just put "Suggested-by: Krzysztof Kozlowski <[email protected]>".
Anyway:
Best regards,
Krzysztof
Re: [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
Quoted 9 lines · Krzysztof Kozlowski
Quoted 3 lines · Gustavo A. R. Silva
Move this enum to
rtc-s5m.conce it is meaningless to others drivers [1].Instead of external link (which might or might not work soon) you can just put "Suggested-by: Krzysztof Kozlowski <[email protected]>".
I got it.
I'll do that next time.
Quoted 3 lines
Anyway:
Reviewed-by Krzysztof Kozlowski <[email protected]>
Thanks for reviewing it.
--
Gustavo
Re: [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
In reply to Gustavo A. R. SilvaQuoted 8 lines · Gustavo A. R. Silva
Move this enum to
rtc-s5m.conce it is meaningless to others drivers [1].[1] https://marc.info/?l=linux-rtc&m=152060068925948&w=2
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/rtc/rtc-s5m.c | 11 +++++++++++ include/linux/mfd/samsung/rtc.h | 11 -----------
I don't think this will conflict with anything (unless some major works are carried out within the next few weeks - in which case I'll need a pull-request, but for now ...)
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 2/2 rtc: s5m: Remove VLA usage
In reply to Gustavo A. R. SilvaIn preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
Quoted 1 line
From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
--- drivers/rtc/rtc-s5m.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/rtc/rtc-s5m.c +8 -6
@@ -47,6 +47,8 @@ enum {RTC_MONTH ,RTC_YEAR1 ,RTC_YEAR2 , +/* Make sure this is always the last enum name. */ + RTC_MAX_NUM_TIME_REGS };/*
@@ -378,7 +380,7 @@ static void s5m8763_tm_to_data(struct rtc_time *tm, u8 *data)static int s5m_rtc_read_time (struct device *dev,struct rtc_time *tm) {struct s5m_rtc_info *info =dev_get_drvdata (dev); -u8 data[info->regs->regs_count]; +u8 data[RTC_MAX_NUM_TIME_REGS ];int ret;if (info->regs->read_time_udr_mask) {
@@ -424,7 +426,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)static int s5m_rtc_set_time (struct device *dev,struct rtc_time *tm) {struct s5m_rtc_info *info =dev_get_drvdata (dev); -u8 data[info->regs->regs_count]; +u8 data[RTC_MAX_NUM_TIME_REGS ];int ret =0 ;switch (info->device_type) {
@@ -461,7 +463,7 @@ static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm)static int s5m_rtc_read_alarm (struct device *dev,struct rtc_wkalrm *alrm) {struct s5m_rtc_info *info =dev_get_drvdata (dev); -u8 data[info->regs->regs_count]; +u8 data[RTC_MAX_NUM_TIME_REGS ];unsigned int val;int ret, i;
@@ -511,7 +513,7 @@ static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)static int s5m_rtc_stop_alarm (struct s5m_rtc_info *info) { -u8 data[info->regs->regs_count]; +u8 data[RTC_MAX_NUM_TIME_REGS ];int ret, i;struct rtc_time tm;
@@ -556,7 +558,7 @@ static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info)static int s5m_rtc_start_alarm (struct s5m_rtc_info *info) {int ret; -u8 data[info->regs->regs_count]; +u8 data[RTC_MAX_NUM_TIME_REGS ];u8 alarm0_conf;struct rtc_time tm;
@@ -609,7 +611,7 @@ static int s5m_rtc_start_alarm(struct s5m_rtc_info *info)static int s5m_rtc_set_alarm (struct device *dev,struct rtc_wkalrm *alrm) {struct s5m_rtc_info *info =dev_get_drvdata (dev); -u8 data[info->regs->regs_count]; +u8 data[RTC_MAX_NUM_TIME_REGS ];int ret;switch (info->device_type) {
Signature · 1 line
2.7.4
Re: [PATCH 2/2] rtc: s5m: Remove VLA usage
Quoted 8 lines · Gustavo A. R. Silva
In preparation to enabling -Wvla, remove VLAs and replace them with fixed-length arrays instead.
From a security viewpoint, the use of Variable Length Arrays can be a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug.
Quoted 7 lines
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/rtc/rtc-s5m.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
Best regards,
Krzysztof
Alexandre Belloni
maintainerHi,
Quoted 9 lines · Gustavo A. R. Silva
This patchset aims to remove VLA usage from rtc-s5m.
The first patch moves an enum from
rtc.htortc-s5m.c, as this is the only driver in which such enum is actually being used [1].The second patch adds the enum name
RTC_MAX_NUM_TIME_REGS, which will be used as a maximum length to the current VLAs, hence turning them into fixed-length arrays instead.
Quoted 8 lines
[1] https://marc.info/?l=linux-rtc&m=152060068925948&w=2
Thanks
Gustavo A. R. Silva (2):
rtc: s5m: move enum fromrtc.htortc-s5m.c
rtc: s5m: Remove VLA usage
Both applied, thanks.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Quoted 14 lines · Alexandre Belloni
Hi,
Quoted 11 lines · Gustavo A. R. Silva
This patchset aims to remove VLA usage from rtc-s5m.
The first patch moves an enum from
rtc.htortc-s5m.c, as this is the only driver in which such enum is actually being used [1].The second patch adds the enum name
RTC_MAX_NUM_TIME_REGS, which will be used as a maximum length to the current VLAs, hence turning them into fixed-length arrays instead.
Quoted 9 lines
Quoted 6 lines
Thanks
Gustavo A. R. Silva (2):
rtc: s5m: move enum fromrtc.htortc-s5m.c
rtc: s5m: Remove VLA usageBoth applied, thanks.
Awesome.
Thank you.
--
Gustavo