On Wed, May 29, 2019 at 9:57 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote: > > On 05/28, Deepa Dinamani wrote: > > > > I agree that signal handller being called and return value not being > > altered is an issue with other syscalls also. I was just wondering if > > some userspace code assumption would be assuming this. This is not a > > kernel bug. > > > > But, I do not think we have an understanding of what was wrong in > > 854a6ed56839a anymore since you pointed out that my assumption was not > > correct that the signal handler being called without errno being set > > is wrong. > > Deepa, sorry, I simply can't parse the above... most probably because of > my bad English. Ok, All I meant was that I had thought a signal handler being invoked without the error value reflecting it was wrong. That is what I had thought was wrong with 854a6ed56839a. Now, that we agree that signal handler can be invoked without the errno returning success, I thought I did not know what is wrong with 854a6ed56839a anymore. But, you now pointed out that the signals we care about should not be delivered after an event has been ready. This points out to what was wrong with 854a6ed56839a. Thanks. > > One open question: this part of epoll_pwait was already broken before > > 854a6ed56839a. Do you agree? > > > > if (err == -EINTR) { > > memcpy(¤t->saved_sigmask, &sigsaved, > > sizeof(sigsaved)); > > set_restore_sigmask(); > > } else > > set_current_blocked(&sigsaved); > > I do not understand why do you think this part was broken :/ Ok, because of your other statement that the signals the application cares about do not want to know about signals they care about after an event is ready this is also not a problem. > > Or, I could revert the signal_pending() check and provide a fix > > something like below(not a complete patch) > > ... > > > -void restore_user_sigmask(const void __user *usigmask, sigset_t *sigsaved) > > +int restore_user_sigmask(const void __user *usigmask, sigset_t > > *sigsaved, int sig_pending) > > { > > > > if (!usigmask) > > return; > > > > /* > > * When signals are pending, do not restore them here. > > * Restoring sigmask here can lead to delivering signals that the above > > * syscalls are intended to block because of the sigmask passed in. > > */ > > + if (sig_pending) { > > current->saved_sigmask = *sigsaved; > > set_restore_sigmask(); > > return; > > } > > > > @@ -2330,7 +2330,8 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct > > epoll_event __user *, events, > > > > error = do_epoll_wait(epfd, events, maxevents, timeout); > > > > - restore_user_sigmask(sigmask, &sigsaved); > > + signal_detected = restore_user_sigmask(sigmask, &sigsaved, > > error == -EINTR); > > I fail to understand this pseudo-code, sorry. In particular, do not understand > why restore_user_sigmask() needs to return a boolean. That was a remnant from the other patch. Return type needs to be void. > The only thing I _seem to_ understand is the "sig_pending" flag passed by the > caller which replaces the signal_pending() check. Correct. This is what is the main change I was proposing. > Yes, this is what I think we > should do, and this is what I tried to propose from the very beginning in my > 1st email in this thread. This was not clear to me in your first response that you did not want the signal_pending() check in restore_user_sigmask(). : https://lore.kernel.org/lkml/20190522150505.GA4915@xxxxxxxxxx/ "Ugh. I need to re-check, but at first glance I really dislike this change. I think we can fix the problem _and_ simplify the code. Something like below. The patch is obviously incomplete, it changes only only one caller of set_user_sigmask(), epoll_pwait() to explain what I mean. restore_user_sigmask() should simply die. Although perhaps another helper makes sense to add WARN_ON(test_tsk_restore_sigmask() && !signal_pending)." -Deepa