Skip to content

Passing parameters to VAR blocks in stateful POUs is not validated and can result in termination of the process by the kernel #1201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mhasel opened this issue Apr 15, 2024 · 0 comments · Fixed by #1233
Labels
bug Something isn't working high-priority validation candidate for syntactic or semantic validation

Comments

@mhasel
Copy link
Member

mhasel commented Apr 15, 2024

Describe the bug
We currently do not validate against passing parameters to function blocks outside of the intended variable blocks.

Given we define a function block without input parameters:

FUNCTION_BLOCK FOO
    VAR
        val : STRING[65536];
    END_VAR
END_FUNCTION_BLOCK

If we then try to pass in a parameter regardless, like so:

FUNCTION main : DINT
VAR
    str: STRING[65536];
    fb: FOO;
END_VAR
    fb(str);
END_FUNCTION

Then we either compile without error (for small enough parameters) or the kernel terminates compilation (large aggregate params) and the console prints Killed.

To Reproduce
Copy the above example in a file and then try to compile with plc file.st

Expected behavior
Aborting compilation with a diagnostic rather than the kernel killing the process.

Additional context
Generating IR for this example will fail in the verify stage:

error[E071]: /tmp/.tmpdVP6Xf/target/demo.st.ll:19:13: error: invalid forward reference to function 'FOO' with wrong type: expected 'void (%FOO*)*' but was 'void (%FOO*, [65537 x i8])*'
  call void @FOO(%FOO* %fb, [65537 x i8] %load_str)
            ^

Querying the kernel with dmesg -T| grep -E -i -B100 'killed process':

[Mon Apr 15 14:48:54 2024] [  54051]  1000 54051  2103862  1761352 14778368    33858             0 plc
[Mon Apr 15 14:48:54 2024] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/,task=plc,pid=54051,uid=1000
[Mon Apr 15 14:48:54 2024] Out of memory: Killed process 54051 (plc) total-vm:8415448kB, anon-rss:7045404kB, file-rss:4kB, shmem-rss:0kB, UID:1000 pgtables:14432kB oom_score_adj:0

Tested in WSL and native Ubuntu

@mhasel mhasel added bug Something isn't working validation candidate for syntactic or semantic validation high-priority labels Apr 15, 2024
@mhasel mhasel changed the title Passing a large aggregate variable to a VAR block in a FUNCTION_BLOCK results in termination of the proccess by the kernel Passing parameters to VAR blocks in stateful POUs is not validated and can result in termination of the proccess by the kernel Apr 15, 2024
@mhasel mhasel changed the title Passing parameters to VAR blocks in stateful POUs is not validated and can result in termination of the proccess by the kernel Passing parameters to VAR blocks in stateful POUs is not validated and can result in termination of the process by the kernel Apr 18, 2024
@mhasel mhasel linked a pull request Jun 6, 2024 that will close this issue
volsa added a commit that referenced this issue Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high-priority validation candidate for syntactic or semantic validation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant