Skip to content
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

Fix for rpmdb with SQLite3 backend #317

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

radosroka
Copy link
Member

When the daemon is reloading the trustdb, and the rpmdb file is concurrently processed as an object, the file descriptor is closed at the end of evaluation. A close() on the SQLite database file causes the locks to be dropped. As a result, subsequent RPM installations can corrupt the RPM database when fapolicyd is running.

@radosroka radosroka force-pushed the rpmdb-fix branch 2 times, most recently from 69b6834 to 106ce30 Compare October 24, 2024 12:10
@stevegrubb
Copy link
Member

In init_fd_buffer, why use calloc if you are going to use memset to initialize with? (calloc would be unnecessarily initializing everything to 0.) Also, why use rlimits? It allows you to have a lot of files open. Wouldn't 16 suffice?

@radosroka
Copy link
Member Author

radosroka commented Oct 25, 2024

In init_fd_buffer, why use calloc if you are going to use memset to initialize with? (calloc would be unnecessarily initializing everything to 0.) Also, why use rlimits? It allows you to have a lot of files open. Wouldn't 16 suffice?

I forget to change calloc back to malloc. I wanted to calculate size of the buffer from the maximum file descriptors available because more is better. During the testing I've seen that "rpm -i" can generate 5-6 fds.

This is recipe how to get rid of lock. When these rpms are not installed before it can definitely corrupt the database for the daemon. It causes either reading of incorrect data or SIGBUS or any other error from rpmdb.

# yumdowndloader tcsh
# rpm -i tcsh* # this will install normally
# rpm -i tcsh* ; rpm -i tcsh* ; # this needs to safe these 5-6 fds
# rpm -i tcsh* ; rpm -i tcsh* ; rpm -i tcsh* ;  # this needs to safe these 10-12 fds
...

@stevegrubb
Copy link
Member

One last thing, I apologize for not catching this yesterday, when initializing the fd_buffer with memset shouldn't that be a "for" loop setting each integer to -1? memset works at the char level. It is more correct to set an integer array entry to an integer value.

@stevegrubb
Copy link
Member

Also, in fapolicyd.c around line 574, we set the rlimit to 16K. Meaning that the fd_buffer size will be 4K. That's why I was asking if we can just declare it to be 16 and not derive it from rlimits?

@radosroka
Copy link
Member Author

Also, in fapolicyd.c around line 574, we set the rlimit to 16K. Meaning that the fd_buffer size will be 4K. That's why I was asking if we can just declare it to be 16 and not derive it from rlimits?

I noticed that in valgrind, setting rlimit doesn't work. I believe this can be also the case for some machines with very low resources. In such case limit can drop to 1024, therefore manual setting for 512 because 256 would be too low. If fd buffer set to 16k and limit is 1024 it isn't hard to force the daemon to run out from fds.

When the daemon is reloading the trustdb, and the rpmdb file is concurrently processed as an object, the file descriptor is closed at the end of evaluation.
A close() on the SQLite database file causes the locks to be dropped.
As a result, subsequent RPM installations can corrupt the RPM database when fapolicyd is running.

Signed-off-by: Radovan Sroka <[email protected]>
@radosroka radosroka merged commit 23fef4c into linux-application-whitelisting:main Oct 27, 2024
18 of 30 checks passed
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