max31855: reject personality above 15 at load time - #4314
Conversation
| Pins and parameters whose "if condition" or "[maxsize : condsize]" evaluates to false or zero are not exported, | ||
| and the instance memory for them is left zeroed, so accessing such a pin from a function body dereferences a NULL pointer and crashes the realtime process. | ||
| A component that uses 'personality' to size its pins or parameters should validate the value in EXTRA_SETUP() | ||
| and return -EINVAL with a clear message for configurations that would export no pins: |
There was a problem hiding this comment.
These are very long sentences. Maybe split it up in smaller sentences.
It also ends with a colon?
There was a problem hiding this comment.
Split in shorter sentences.
The sentence was preamble to the code, the colon was the glue, made it more specific.
There was a problem hiding this comment.
See if it reads better now, or did I overdo it?
0d827e8 to
f419045
Compare
|
What about: [NOTE]
----
If a component uses personality, then it should generally check its value.
The value of personality is zero if the 'personality=N' argument is not provided to loadrt.
Any unconditional access to pins or params created by personality constraints, when zero, causes a crash.
Pins and params are not created when personality is zero and its memory remains NULL.
Accessing a not created pin or param accesses a NULL pointer, which inevitably leads to a crash.
You can use a test in EXTRA_SETUP() to test the acceptable values of personality for your component.
You should return -EINVAL if your conditions are not met.
Example testing personality:
[source,c]
...
---- |
|
A real bikeshed moment :-) |
Follow-up to LinuxCNC#4302. The pins are sized by (personality & 0xf) but the function indexes them with the raw value capped at 15, so personality=16 exports zero sensor pins while the function accesses 15 of them, killing rtapi_app when the thread runs. Reject in EXTRA_SETUP with -EINVAL so the failure shows up at loadrt time. Also note in comp.adoc that components with personality-sized pins should validate the value in EXTRA_SETUP, with an example.
f419045 to
39c69b2
Compare
|
Continuing the bikeshed painting: I kept your first two sentences and the remedy paragraph verbatim, and merged the three middle ones into a cause-then-effect pair, since they said "crash" twice and "a not created pin" read clunky to me. I feel it reads better like this, but your version is acceptable to me too if you prefer it. |
|
I like your color too. |
Follow-up to the discussion on #4302.
max31855 sizes its sensor pins by
(personality & 0xf)but indexes them with the raw value capped at 15.personality=16exports zero sensor pins while the function accesses 15 of them, dereferencing NULL pin pointers and killing rtapi_app as soon as the function runs in a thread.Repro (uspace sim, RIP build):
Before: rtapi_app dies within one thread period of
start. Silent in POSIX fallback: halrun still exits 0 and halcmd keeps answering from shm; onlypgrep -x rtapi_appshows it.After:
loadrtfails withmax31855: personality must be at most 15 (use personality=N to set the number of sensors).Also adds the agreed comp.adoc note: components with personality-sized pins should validate the value in EXTRA_SETUP and return -EINVAL, with an example.