[CRIU] [PATCH] zdtm: fix sigpending to check blocked signal masks
Andrew Vagin
avagin at parallels.com
Wed May 22 07:52:59 EDT 2013
On Wed, May 22, 2013 at 03:48:26PM +0400, Pavel Emelyanov wrote:
> On 05/22/2013 03:46 PM, Andrey Vagin wrote:
> > Here are a few bugs which hide each other.
>
* memcmp(&newset, &oldset, sizeof(newset) returns 0 is masks are equal.
* sigprocmask return sigset_t and it contains extra bits for the future,
so we need to initialize all this bits otherwise they will contain
random data.
> Plz, describe them.
>
> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
> > ---
> > test/zdtm/live/static/sigpending.c | 18 ++++++++++++++----
> > 1 file changed, 14 insertions(+), 4 deletions(-)
> >
> > diff --git a/test/zdtm/live/static/sigpending.c b/test/zdtm/live/static/sigpending.c
> > index ce47f60..05471f9 100644
> > --- a/test/zdtm/live/static/sigpending.c
> > +++ b/test/zdtm/live/static/sigpending.c
> > @@ -91,6 +91,9 @@ static void *thread_fn(void *args)
> > sigset_t blockmask, oldset, newset;
> > struct sigaction act;
> >
> > + memset(&oldset, 0, sizeof(oldset));
> > + memset(&newset, 0, sizeof(oldset));
> > +
sigprocmask return sigset_t and it contains extra bits for the future,
so we need to initialize all this bits otherwise they will contain
random data.
> > sigfillset(&blockmask);
> > sigdelset(&blockmask, SIGTERM);
> >
> > @@ -99,7 +102,7 @@ static void *thread_fn(void *args)
> > return NULL;
> > }
> >
> > - if (sigprocmask(SIG_BLOCK, NULL, &oldset) == -1) {
> > + if (sigprocmask(SIG_SETMASK, NULL, &oldset) == -1) {
> > err("sigprocmask");
> > return NULL;
> > }
> > @@ -125,7 +128,9 @@ static void *thread_fn(void *args)
> > return NULL;
> > }
> >
> > - if (!memcmp(&newset, &oldset, sizeof(newset))) {
> > + sigdelset(&oldset, SIGTRAP);
> > + sigdelset(&newset, SIGTRAP);
SIG_TRAP is used by ptrace and will be unblocked.
> > + if (memcmp(&newset, &oldset, sizeof(newset))) {
> > fail("The signal blocking mask was changed");
> > numsig = INT_MAX;
> > }
> > @@ -161,6 +166,9 @@ int main(int argc, char ** argv)
> > pthread_t pthrd;
> > int i;
> >
> > + memset(&oldset, 0, sizeof(oldset));
> > + memset(&newset, 0, sizeof(oldset));
> > +
> > test_init(argc, argv);
> > pthread_mutex_init(&exit_lock, NULL);
> > pthread_mutex_lock(&exit_lock);
> > @@ -182,7 +190,7 @@ int main(int argc, char ** argv)
> > return -1;
> > }
> >
> > - if (sigprocmask(SIG_BLOCK, &oldset, NULL) == -1) {
> > + if (sigprocmask(SIG_BLOCK, NULL, &oldset) == -1) {
A current mask will be saved in a third argument
> > err("sigprocmask");
> > return -1;
> > }
> > @@ -242,7 +250,9 @@ int main(int argc, char ** argv)
> > pthread_mutex_unlock(&exit_lock);
> > pthread_join(pthrd, NULL);
> >
> > - if (!memcmp(&newset, &oldset, sizeof(newset))) {
> > + sigdelset(&oldset, SIGTRAP);
> > + sigdelset(&newset, SIGTRAP);
> > + if (memcmp(&newset, &oldset, sizeof(newset))) {
memcmp(&newset, &oldset, sizeof(newset) returns 0 is masks are equal.
> > fail("The signal blocking mask was changed");
> > return 1;
> > }
> >
>
>
More information about the CRIU
mailing list