By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release.
Bug 3025 - sigset_t used without initialization in kdesktop_lock
Summary: sigset_t used without initialization in kdesktop_lock
Status: RESOLVED FIXED
Alias: None
Product: TDE
Classification: Unclassified
Component: tdebase (show other bugs)
Version: R14.0.x [Trinity]
Hardware: amd64 Debian Buster
: P5 normal
Assignee: Timothy Pearson
URL:
Depends on:
Blocks: R14.1.0
  Show dependency treegraph
 
Reported: 2019-07-13 07:04 CDT by mgb-trinity
Modified: 2019-07-21 08:49 CDT (History)
4 users (show)

See Also:
Compiler Version:
TDE Version String:
Application Version:
Application Name:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mgb-trinity 2019-07-13 07:04:17 CDT
In tdebase/kdesktop/lock/main.cpp:

        while (1 == 1) {
                sigset_t new_mask;
                sigset_t orig_mask;

                // Block reception of all signals in this thread
                sigprocmask(SIG_BLOCK, &new_mask, NULL);

sigset_t should not be used without initialization.  It looks like sigfillset was omitted here resulting in undefined/random behavior.

This may or may not explain some of the observed kdesktop_lock misbehavior.
Comment 1 Slávek Banko 2019-07-14 07:59:36 CDT
Since there is yet another part to discuss, and since TGW is more appropriate for discussing the proposed patch, there is a pull request in TGW:

https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/pulls/42
Comment 2 mgb-trinity 2019-07-14 11:10:30 CDT
I may have been mistaken to suggest sigfillset.

There's another supposed block of all signals at line 460 but new_mask at this point contains only the five signals of interest.

I'm guessing that someone wrote the new_mask initialization starting at line 390 and the "(signalled_run == FALSE)" loop starting at line 433 and probably got them basically right, but there was a race condition before and after this code section.  So someone else added the "block all signals" and got it wrong.

Maybe the comments about blocking all signals really mean to block the five signals of interest.  Maybe all that is needed is for the existing initialization of new_mask to be moved before its first use, rather than using sigfillset which would lose any pre-existing signal mask without saving it.

If the code was really supposed to block all signals there would be no need to record orig_mask at line 449.

YMMV.  I've been staring at this file for days and there's still a lot I don't understand.
Comment 3 Slávek Banko 2019-07-14 14:03:59 CDT
I noticed one more important thing - the part where new_mask is used without initialization is new change in master branch but not in stable branch. Therefore, the stable branch may not be affected by this issue.
Comment 4 mgb-trinity 2019-07-14 17:35:19 CDT
> the part where new_mask is used without initialization is new change in master branch but not in stable branch.

Are you sure?

I was looking at code through: https://git.trinitydesktop.org/cgit/
but if there's a "git blame" function there I couldn't find it.  I did check the log there and didn't see anything relevant.

So I did "GIT_ASKPASS=echo git clone --recursive https://anonymous@scm.trinitydesktop.org/scm/git/tde" and ran "git blame" where I see the use of uninitialized new_mask in Tim's original check in of KDE 3.5:

b5cb2797d (Timothy Pearson 2015-09-21 15:39:58 -0500 242)               sigset_t new_mask;
b5cb2797d (Timothy Pearson 2015-09-21 15:39:58 -0500 243)               sigset_t orig_mask;
b5cb2797d (Timothy Pearson 2015-09-21 15:39:58 -0500 244)
b5cb2797d (Timothy Pearson 2015-09-21 15:39:58 -0500 245)               // Block reception
of all signals in this thread
b5cb2797d (Timothy Pearson 2015-09-21 15:39:58 -0500 246)               sigprocmask(SIG_BLO
CK, &new_mask, NULL);

Of course, if there's a race, then disabling signals in main is probably still racy.  They probably need to be disabled before this process is created, just as they are disabled before this process's own lock thread is created.

Meanwhile what got me here in the first place is trying to figure out why desktop_lock processes were crashing with multiple non-xinerama screens.

So we have two aspects: multiple non-xinerama screens and signal masking/races.  I don't know about you but I'm certainly well short of understanding exactly how to do them right.
Comment 5 Slávek Banko 2019-07-15 10:48:34 CDT
Yes, I'm sure the code is different between master and r14.0.x branch.

You can look at the description in the pull-request and the attached patch that now addresses for the master branch both sigprocmask calls with the comment // Block reception of all signals in this thread

https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/pulls/42/files

While in r14.0.x a branch is only the second call that follows a code that sets values to new_mask. It is likely that sigfillset(& new_mask) should be used for this call, but it is certainly not a call without initialization, as in the case of a master branch.

See:

https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/src/branch/r14.0.x/kdesktop/lock/main.cc#L241
https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/src/branch/r14.0.x/kdesktop/lock/main.cc#L379
https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/src/branch/r14.0.x/kdesktop/lock/main.cc#L417
https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/src/branch/r14.0.x/kdesktop/lock/main.cc#L451
Comment 6 mgb-trinity 2019-07-15 11:29:39 CDT
Thanks.  My mistake.  I had neglected to also switch the submodule to the r14.0.x branch.

BTW, are you deleting https://git.trinitydesktop.org/cgit/ or is it breaking?  Now when I click on a submodule e.g. tdebase I get no such file or directory.  Was OK a few days ago.
Comment 7 Michele Calgaro 2019-07-16 09:45:39 CDT
> While in r14.0.x a branch is only the second call that follows a code that sets values 
> to new_mask. It is likely that sigfillset(& new_mask) should be used for this call, but 
> it is certainly not a call without initialization, as in the case of a master branch.
I agree, looks like sigfillset is missing in r14.0.x branch too before the last call.
Comment 8 mgb-trinity 2019-07-18 16:26:41 CDT
This bug report is my mistake.  I was looking at the wrong branch because I had neglected to switch the submodule to the r14.0.x branch.  (I dislike submodules!)

I believe Slávek's proposed patch is similarly faulty.

Tim appears to have fixed this problem in the r14.0.x back in 2015.

There's still a problem with desktop_lock on multiple non-xinerama screens but this is not the solution.

Would Slávek like to mark this as RESOLVED/INVALID or similar?
Comment 9 Michele Calgaro 2019-07-21 08:49:10 CDT
We have merged PR #42 which initializes new_mask correctly.
https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/pulls/42