Skip to content

max31855: reject personality above 15 at load time - #4314

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:personality-guards
Open

max31855: reject personality above 15 at load time#4314
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:personality-guards

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

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=16 exports 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):

loadrt threads name1=t period1=100000 fp1=0
loadrt max31855 personality=16
addf max31855.0.bitbang-spi t
start

Before: rtapi_app dies within one thread period of start. Silent in POSIX fallback: halrun still exits 0 and halcmd keeps answering from shm; only pgrep -x rtapi_app shows it.
After: loadrt fails with max31855: 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.

Comment thread docs/src/hal/comp.adoc Outdated
Comment on lines +519 to +522
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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are very long sentences. Maybe split it up in smaller sentences.
It also ends with a colon?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split in shorter sentences.
The sentence was preamble to the code, the colon was the glue, made it more specific.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if it reads better now, or did I overdo it?

Comment thread docs/src/hal/comp.adoc
@grandixximo
grandixximo force-pushed the personality-guards branch 4 times, most recently from 0d827e8 to f419045 Compare August 1, 2026 14:08
@BsAtHome

BsAtHome commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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]
...

----

@BsAtHome

BsAtHome commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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.
@grandixximo

grandixximo commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

[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.
Pins and params whose personality constraint evaluates to zero are not created, and their memory remains NULL.
Unconditionally accessing such a pin or param dereferences a NULL pointer and crashes the realtime process.

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]
----

@BsAtHome

BsAtHome commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

I like your color too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants