* [PATCH 0/2] Remove VLA usage in rtc-s5m
@ 2018-03-10 6:27 Gustavo A. R. Silva
2018-03-10 6:27 ` [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c Gustavo A. R. Silva
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-10 6:27 UTC (permalink / raw)
To: Sangbeom Kim, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
Alessandro Zummo, Alexandre Belloni, Lee Jones
Cc: linux-samsung-soc, linux-rtc, linux-kernel, Kernel Hardening,
Kees Cook, Gustavo A. R. Silva
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(-)
--
2.7.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
2018-03-10 6:27 [PATCH 0/2] Remove VLA usage in rtc-s5m Gustavo A. R. Silva
@ 2018-03-10 6:27 ` Gustavo A. R. Silva
2018-03-11 16:39 ` Krzysztof Kozlowski
2018-03-12 8:54 ` Lee Jones
2018-03-10 6:27 ` [PATCH 2/2] rtc: s5m: Remove VLA usage Gustavo A. R. Silva
2018-03-13 0:35 ` [PATCH 0/2] Remove VLA usage in rtc-s5m Alexandre Belloni
2 siblings, 2 replies; 9+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-10 6:27 UTC (permalink / raw)
To: Sangbeom Kim, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
Alessandro Zummo, Alexandre Belloni, Lee Jones
Cc: linux-samsung-soc, linux-rtc, linux-kernel, Kernel Hardening,
Kees Cook, Gustavo A. R. Silva
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
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
drivers/rtc/rtc-s5m.c | 11 +++++++++++
include/linux/mfd/samsung/rtc.h | 11 -----------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 6deae10..4c363de 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -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.
*
diff --git a/include/linux/mfd/samsung/rtc.h b/include/linux/mfd/samsung/rtc.h
index 48c3c5b..9ed2871 100644
--- a/include/linux/mfd/samsung/rtc.h
+++ b/include/linux/mfd/samsung/rtc.h
@@ -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 */
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] rtc: s5m: Remove VLA usage
2018-03-10 6:27 [PATCH 0/2] Remove VLA usage in rtc-s5m Gustavo A. R. Silva
2018-03-10 6:27 ` [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c Gustavo A. R. Silva
@ 2018-03-10 6:27 ` Gustavo A. R. Silva
2018-03-12 11:14 ` Krzysztof Kozlowski
2018-03-13 0:35 ` [PATCH 0/2] Remove VLA usage in rtc-s5m Alexandre Belloni
2 siblings, 1 reply; 9+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-10 6:27 UTC (permalink / raw)
To: Sangbeom Kim, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
Alessandro Zummo, Alexandre Belloni
Cc: linux-samsung-soc, linux-rtc, linux-kernel, Kernel Hardening,
Kees Cook, 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.
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 <gustavo@embeddedor.com>
---
drivers/rtc/rtc-s5m.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 4c363de..8428455 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -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) {
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
2018-03-10 6:27 ` [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c Gustavo A. R. Silva
@ 2018-03-11 16:39 ` Krzysztof Kozlowski
2018-03-13 3:22 ` Gustavo A. R. Silva
2018-03-12 8:54 ` Lee Jones
1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2018-03-11 16:39 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Sangbeom Kim, Bartlomiej Zolnierkiewicz, Alessandro Zummo,
Alexandre Belloni, Lee Jones, linux-samsung-soc, linux-rtc,
linux-kernel, Kernel Hardening, Kees Cook, Gustavo A. R. Silva
On Sat, Mar 10, 2018 at 7:27 AM, Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
> 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
Instead of external link (which might or might not work soon) you can
just put "Suggested-by: Krzysztof Kozlowski <krzk@kernel.org>".
Anyway:
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
2018-03-10 6:27 ` [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c Gustavo A. R. Silva
2018-03-11 16:39 ` Krzysztof Kozlowski
@ 2018-03-12 8:54 ` Lee Jones
1 sibling, 0 replies; 9+ messages in thread
From: Lee Jones @ 2018-03-12 8:54 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Sangbeom Kim, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
Alessandro Zummo, Alexandre Belloni, linux-samsung-soc,
linux-rtc, linux-kernel, Kernel Hardening, Kees Cook,
Gustavo A. R. Silva
On Sat, 10 Mar 2018, Gustavo A. R. Silva wrote:
> 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
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> 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 ...)
Acked-by: Lee Jones <lee.jones@linaro.org>
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] rtc: s5m: Remove VLA usage
2018-03-10 6:27 ` [PATCH 2/2] rtc: s5m: Remove VLA usage Gustavo A. R. Silva
@ 2018-03-12 11:14 ` Krzysztof Kozlowski
0 siblings, 0 replies; 9+ messages in thread
From: Krzysztof Kozlowski @ 2018-03-12 11:14 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Sangbeom Kim, Bartlomiej Zolnierkiewicz, Alessandro Zummo,
Alexandre Belloni, linux-samsung-soc, linux-rtc, linux-kernel,
Kernel Hardening, Kees Cook, Gustavo A. R. Silva
On Sat, Mar 10, 2018 at 7:27 AM, Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
> 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.
>
> 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 <gustavo@embeddedor.com>
> ---
> drivers/rtc/rtc-s5m.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] Remove VLA usage in rtc-s5m
2018-03-10 6:27 [PATCH 0/2] Remove VLA usage in rtc-s5m Gustavo A. R. Silva
2018-03-10 6:27 ` [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c Gustavo A. R. Silva
2018-03-10 6:27 ` [PATCH 2/2] rtc: s5m: Remove VLA usage Gustavo A. R. Silva
@ 2018-03-13 0:35 ` Alexandre Belloni
2018-03-13 1:17 ` Gustavo A. R. Silva
2 siblings, 1 reply; 9+ messages in thread
From: Alexandre Belloni @ 2018-03-13 0:35 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Sangbeom Kim, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
Alessandro Zummo, Lee Jones, linux-samsung-soc, linux-rtc,
linux-kernel, Kernel Hardening, Kees Cook, Gustavo A. R. Silva
Hi,
On 10/03/2018 at 00:27:02 -0600, Gustavo A. R. Silva wrote:
> 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
>
Both applied, thanks.
--
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] Remove VLA usage in rtc-s5m
2018-03-13 0:35 ` [PATCH 0/2] Remove VLA usage in rtc-s5m Alexandre Belloni
@ 2018-03-13 1:17 ` Gustavo A. R. Silva
0 siblings, 0 replies; 9+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-13 1:17 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Sangbeom Kim, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
Alessandro Zummo, Lee Jones, linux-samsung-soc, linux-rtc,
linux-kernel, Kernel Hardening, Kees Cook, Gustavo A. R. Silva
On 03/12/2018 07:35 PM, Alexandre Belloni wrote:
> Hi,
>
> On 10/03/2018 at 00:27:02 -0600, Gustavo A. R. Silva wrote:
>> 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
>>
>
> Both applied, thanks.
>
Awesome.
Thank you.
--
Gustavo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c
2018-03-11 16:39 ` Krzysztof Kozlowski
@ 2018-03-13 3:22 ` Gustavo A. R. Silva
0 siblings, 0 replies; 9+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-13 3:22 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Sangbeom Kim, Bartlomiej Zolnierkiewicz, Alessandro Zummo,
Alexandre Belloni, Lee Jones, linux-samsung-soc, linux-rtc,
linux-kernel, Kernel Hardening, Kees Cook, Gustavo A. R. Silva
On 03/11/2018 11:39 AM, Krzysztof Kozlowski wrote:
> On Sat, Mar 10, 2018 at 7:27 AM, Gustavo A. R. Silva
> <gustavo@embeddedor.com> wrote:
>> 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
>
> Instead of external link (which might or might not work soon) you can
> just put "Suggested-by: Krzysztof Kozlowski <krzk@kernel.org>".
>
I got it.
I'll do that next time.
> Anyway:
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
>
Thanks for reviewing it.
--
Gustavo
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-03-13 3:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-10 6:27 [PATCH 0/2] Remove VLA usage in rtc-s5m Gustavo A. R. Silva
2018-03-10 6:27 ` [PATCH 1/2] rtc: s5m: Move enum from rtc.h to rtc-s5m.c Gustavo A. R. Silva
2018-03-11 16:39 ` Krzysztof Kozlowski
2018-03-13 3:22 ` Gustavo A. R. Silva
2018-03-12 8:54 ` Lee Jones
2018-03-10 6:27 ` [PATCH 2/2] rtc: s5m: Remove VLA usage Gustavo A. R. Silva
2018-03-12 11:14 ` Krzysztof Kozlowski
2018-03-13 0:35 ` [PATCH 0/2] Remove VLA usage in rtc-s5m Alexandre Belloni
2018-03-13 1:17 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).