ptp: ocp: fix NULL deref in _signal_summary_show
PATCH 1/1 ptp: ocp: fix NULL deref in _signal_summary_show
Sysfs signal show operations can invoke _signal_summary_show before signal_out array elements are initialized, causing a NULL pointer dereference. Add NULL checks for signal_out elements to prevent kernel crashes.
--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ptp/ptp_ocp.c +3 -0
@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val; +if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",
Signature · 1 line
2.47.0
Vadim Fedorenko
maintainerQuoted 16 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 9 lines
drivers/ptp/ptp_ocp.c +3
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val; +if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",
That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
I believe the proper fix is to move ptp_ocp_attr_group_add() closer to the end of ptp_ocp_adva_board_init() like it's done for other boards.
--
pw-bot: cr
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;
Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
The scenario (our case): on ptp_ocp_adva_board_init we
initiate only signals 0 and 1 so 2 and 3 are NULL.
Later ptp_ocp_summary_show runs on all 4 signals and calls _signal_summary_show when calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
struct signal_reg __iomem *reg = bp->signal_out[nr]->mem;
struct ptp_ocp_signal *signal = &bp->signal[nr];
Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Vadim Fedorenko
maintainerQuoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;
^^^
yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (adva_timecard_attrs).
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Quoted 42 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;
Quoted 6 lines
^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).
I can (and will) expose only 2 sma in adva_timecard_attrs, but still ptp_ocp_summary_show runs
on all 4 signals and not only on the on that exposed, is it not a bug?
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Vadim Fedorenko
maintainerQuoted 47 lines · Sagi Maimon
Quoted 45 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
Quoted 6 lines
Quoted 3 lines
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?
Yeah, it's a bug, but different one, and we have to fix it other way.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Quoted 49 lines · Vadim Fedorenko
Quoted 47 lines · Sagi Maimon
Quoted 45 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Vadim Fedorenko
maintainerQuoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have BUILD_BUG_ON() to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Quoted 64 lines · Vadim Fedorenko
Quoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 9 lines
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have
BUILD_BUG_ON()to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.
just to be clear you will write the fix and test it on your HW, so you don't want me to write the fix?
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Vadim Fedorenko
maintainerQuoted 75 lines · Sagi Maimon
Quoted 64 lines · Vadim Fedorenko
Quoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 9 lines
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have
BUILD_BUG_ON()to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.
Quoted 2 lines
just to be clear you will write the fix and test it on your HW, so you don't want me to write the fix?
Well, it would be great if you can write the code which will make SMA functions flexible to the amount of pin the HW has. All our HW has fixed amount of 4 pins that's why the driver was coded with constants. Now your hardware has slightly different amount of pins, so it needs adjustments to the driver to work properly. I just want to be sure that any adjustments will not break my HW - that's what I meant saying I'll test it.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Quoted 80 lines · Vadim Fedorenko
Quoted 75 lines · Sagi Maimon
Quoted 64 lines · Vadim Fedorenko
Quoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 9 lines
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have
BUILD_BUG_ON()to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.Quoted 2 lines
just to be clear you will write the fix and test it on your HW, so you don't want me to write the fix?
Quoted 8 lines
Well, it would be great if you can write the code which will make SMA functions flexible to the amount of pin the HW has. All our HW has fixed amount of 4 pins that's why the driver was coded with constants. Now your hardware has slightly different amount of pins, so it needs adjustments to the driver to work properly. I just want to be sure that any adjustments will not break my HW - that's what I meant saying I'll test it.
Just to be clear (correct me please if I am wrong):
I will write the code, then create a patch and upstream to the vanilla you will test my change on your HW and only then approve the patch
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Vadim Fedorenko
maintainerQuoted 90 lines · Sagi Maimon
Quoted 80 lines · Vadim Fedorenko
Quoted 75 lines · Sagi Maimon
Quoted 64 lines · Vadim Fedorenko
Quoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 9 lines
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have
BUILD_BUG_ON()to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.Quoted 2 lines
just to be clear you will write the fix and test it on your HW, so you don't want me to write the fix?
Quoted 8 lines
Well, it would be great if you can write the code which will make SMA functions flexible to the amount of pin the HW has. All our HW has fixed amount of 4 pins that's why the driver was coded with constants. Now your hardware has slightly different amount of pins, so it needs adjustments to the driver to work properly. I just want to be sure that any adjustments will not break my HW - that's what I meant saying I'll test it.
Quoted 3 lines
Just to be clear (correct me please if I am wrong):
I will write the code, then create a patch and upstream to the vanilla you will test my change on your HW and only then approve the patch
Yes, that's correct
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Quoted 92 lines · Vadim Fedorenko
Quoted 90 lines · Sagi Maimon
Quoted 88 lines · Vadim Fedorenko
Quoted 75 lines · Sagi Maimon
Quoted 64 lines · Vadim Fedorenko
Quoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke
_signal_summary_showbeforesignal_outarray elements are initialized, causing a NULL pointer dereference. Add NULL checks forsignal_outelements to prevent kernel crashes.Fixes b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")Signed-off-by Sagi Maimon <[email protected]>--- drivers/ptp/ptp_ocp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/ptp/ptp_ocp.c +0
-0@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)bool on;u32 val;Quoted 10 lines
drivers/ptp/ptp_ocp.c _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr) · line 3971
Quoted 6 lines
drivers/ptp/ptp_ocp.c +3
-0+if (!bp->signal_out[nr]) +return ; + on = signal->running;sprintf (label,"GEN%d" , nr +1 ); seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 9 lines
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have
BUILD_BUG_ON()to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.Quoted 2 lines
just to be clear you will write the fix and test it on your HW, so you don't want me to write the fix?
Well, it would be great if you can write the code which will make SMA functions flexible to the amount of pin the HW has. All our HW has fixed amount of 4 pins that's why the driver was coded with constants. Now your hardware has slightly different amount of pins, so it needs adjustments to the driver to work properly. I just want to be sure that any adjustments will not break my HW - that's what I meant saying I'll test it.
Quoted 6 lines
Quoted 3 lines
Just to be clear (correct me please if I am wrong):
I will write the code, then create a patch and upstream to the vanilla you will test my change on your HW and only then approve the patchYes, that's correct
On altera we have implemented 2 signals and 4 SMAs (does not make sense, but...) The original fix is regarding struct ptp_ocp_signal signal[4], but on your fix suggestion
you mension SMAs.
So what to do? fix the SMA array or signal array or both?
and if both should we establish some connection between the two meaning if we have only
two SMAs then we can initiate only two signals?
please advise
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr
Vadim Fedorenko
maintainerQuoted 100 lines · Sagi Maimon
Quoted 92 lines · Vadim Fedorenko
Quoted 90 lines · Sagi Maimon
Quoted 88 lines · Vadim Fedorenko
Quoted 75 lines · Sagi Maimon
Quoted 64 lines · Vadim Fedorenko
Quoted 54 lines · Sagi Maimon
Quoted 52 lines · Vadim Fedorenko
Quoted 50 lines · Sagi Maimon
Quoted 48 lines · Vadim Fedorenko
Quoted 33 lines · Sagi Maimon
Quoted 21 lines · Vadim Fedorenko
Quoted 19 lines · Sagi Maimon
Sysfs signal show operations can invoke _signal_summary_show before
signal_out array elements are initialized, causing a NULL pointer
dereference. Add NULL checks for signal_out elements to prevent kernel
crashes.Fixes: b325af3cfab9 ("ptp: ocp: Add signal generators and update sysfs nodes")
Signed-off-by: Sagi Maimon <[email protected]>
---
drivers/ptp/ptp_ocp.c | 3 +++
1 file changed, 3 insertions(+)diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 7945c6be1f7c..4c7893539cec 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -3963,6 +3963,9 @@ _signal_summary_show(struct seq_file *s, struct ptp_ocp *bp, int nr)
bool on;
u32 val;Quoted 10 lines
Quoted 6 lines
+ if (!bp->signal_out[nr])
+ return;
+
on = signal->running;
sprintf(label, "GEN%d", nr + 1);
seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d",That's not correct, the dereference of bp->signal_out[nr] happens before the check. But I just wonder how can that even happen?
Quoted 7 lines
The scenario (our case): on
ptp_ocp_adva_board_initwe
initiate only signals 0 and 1 so 2 and 3 are NULL.
Laterptp_ocp_summary_showruns on all 4 signals and calls_signal_summary_showwhen calling signal 2 or 3 the dereference occurs.
can you please explain: " the dereference of bp->signal_out[nr] happens before the check", where exactly? do you mean in those lines:
structsignal_reg__iomem*reg = bp->signal_out[nr]->mem;^^^yes, this is the line which dereferences the pointer.
but in case you have only 2 pins to configure, why the driver exposes 4 SMAs? You can simply adjust the attributes (
adva_timecard_attrs).Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I can (and will) expose only 2 sma in
adva_timecard_attrs, but stillptp_ocp_summary_showruns
on all 4 signals and not only on the on that exposed, is it not a bug?Yeah, it's a bug, but different one, and we have to fix it other way.
Do you want to instruct me how to fix it , or will you fix it?
Quoted 9 lines
well, the original device structure was not designed to have the amount of SMAs less than 4. We have to introduce another field to store actual amount of SMAs to work with, and adjust the code to check the value. The best solution would be to keep maximum amount of 4 SMAs in the structure but create a helper which will init new field and will have
BUILD_BUG_ON()to prevent having more SMAs than fixed size array for them. That will solve your problem, but I will need to check it on the HW we run.Quoted 2 lines
just to be clear you will write the fix and test it on your HW, so you don't want me to write the fix?
Well, it would be great if you can write the code which will make SMA functions flexible to the amount of pin the HW has. All our HW has fixed amount of 4 pins that's why the driver was coded with constants. Now your hardware has slightly different amount of pins, so it needs adjustments to the driver to work properly. I just want to be sure that any adjustments will not break my HW - that's what I meant saying I'll test it.
Quoted 6 lines
Quoted 3 lines
Just to be clear (correct me please if I am wrong):
I will write the code, then create a patch and upstream to the vanilla you will test my change on your HW and only then approve the patchYes, that's correct
Quoted 9 lines
On altera we have implemented 2 signals and 4 SMAs (does not make sense, but...) The original fix is regarding struct
ptp_ocp_signalsignal[4], but on your fix suggestion
you mension SMAs.
So what to do? fix the SMA array or signal array or both?
and if both should we establish some connection between the two meaning if we have only
two SMAs then we can initiate only two signals?
please advise
Ok, now I got it. Previously, the ptp_ocp driver assumed that the amount of SMAs is equal to the amount signals supported as well as frequency outputs and always equals to 4. With the details you provided the assumption is wrong and we have to make proper code for such cases.
I would suggest to introduce 3 fields of u8 which will store the real amount of SMAs/signals/frequencies supported by probed hardware. And reuse this fields in any show/set functions.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
struct
ptp_ocp_signal*signal = &bp->signal[nr];Quoted 5 lines
I believe the proper fix is to move
ptp_ocp_attr_group_add()closer to the end ofptp_ocp_adva_board_init()like it's done for other boards.--
pw-bot: cr