Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1101419yba; Fri, 3 May 2019 16:16:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIVZqLH9Zij8NPIJl0yCr5gfM1Ywdg6Qx8Ce9UvxMkBFaijkLabw6SqFJwiOoXFxqvdPSh X-Received: by 2002:a17:902:2862:: with SMTP id e89mr14468958plb.203.1556925364895; Fri, 03 May 2019 16:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556925364; cv=none; d=google.com; s=arc-20160816; b=vXChFAODNcFeiIsdIula647HXfPscTnwc7C8pioGPbBza2x3KiudgiUnT6f8esQ6mL Vld6ODoIi8Abv02qng/JaP5lDkiR0pITIVx905sBtTxlocYXrL5yqURAbYaj4IAw7PUh la+EaboClpc1E4HC2tBApS8dBhwSAFU3BX7shH1eOw8rBGn2vlTgMU97DSbMCa1heE4k Lm2i2GTm65Uw8ruKBm4tSvuV/996GkBYsVRnVvaRP5xm/GVd8lDeOId9bdlt8f6evl0L cNeZKuTBKso3SFl0ssmq1wT60/nmeRZwrxcncUV0k63ZDli02AKNbFI0dttE9jRQI8wW 2vEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QpmsefFkKENLhwDrCpj25TPAnORDkEylQ4qkeca+hkQ=; b=rSudkS8uvy+DQyXAiDGn1kypnbXJzTzcJpbDOQThNmVz475b9ojdXlyAfnT5HkmdUw ftdOkQBfQEznAerewS2m4hP6YHJLoffza4cBneOQ9PxtSIrs9VxZUD6RwXmMvA42xxQ/ nYagzrBxthTywIR6qKl2QeSMtR579FzGeiyAyiNHBxEaz6VW1vk2ZAtwQd5Za5JWT91o 3gbcA5Mc38UKeHc6CGakwOAgtDaxQw7ar1CJs2CNDMsSsGPqcHlw0xs6ZaPMi795W9gz y+OkOXiNPVT3t7nvPDEs+GFmDojizTfPrvfAh22Rs+ZmThbcQ5b1pZMZJpka8kPkla1M w3LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WniCcG2i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si4086656pgp.378.2019.05.03.16.15.49; Fri, 03 May 2019 16:16:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WniCcG2i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726558AbfECWyI (ORCPT + 99 others); Fri, 3 May 2019 18:54:08 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:46729 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfECWyH (ORCPT ); Fri, 3 May 2019 18:54:07 -0400 Received: by mail-io1-f68.google.com with SMTP id m14so6499814ion.13; Fri, 03 May 2019 15:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QpmsefFkKENLhwDrCpj25TPAnORDkEylQ4qkeca+hkQ=; b=WniCcG2iJ9enM4hYM+5hQyzBCu07Qqs6sOBsDQG4m51/PHvGW8OGhFgCrAvItUNIcu 1mKpcAPc59g+Etix2JDZsL+siLgOXFYVPhBPll/ctjIX6BsIx/15NHo7F7Xqna11BD/Q rR/SvzKuXmKNRkDegy3m0TZh66MkGWQzJ+cfOIwzmQL8qQ7zkL+kYhPKuSGveGOUBevU qkwe5EmxZEJm3POkcoXntoSiNnxjGCzodEsCAxK6TDVzfxWy9xec1xx+FuIjStoK1OXz QAW7WpEAIHdjLBN68BgQ49nTVeLvVClfBT2gtD4GVZxZPK2HVHtfYEsgwEH0hkuNUopV gnlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QpmsefFkKENLhwDrCpj25TPAnORDkEylQ4qkeca+hkQ=; b=nuMwKry3l0hiHg76Od5s0pQhVdQNlYAyEoD4jllcafMlhiZkIt7ucM2Ly/1kKyOP5q Hm3CIjfdTuEDFWTYmUS3KYWwyKpkKrfXEsxs+lZSh8Gcef4Ul0YWiqxuNmC6BnP1M8u8 StevGri7RCkB8xK6SJWWlVs8p3HcNKRJ8ef5xQ/lR+t6lEB7yMQSxyXX9VGZNKuqCu5t rEyCMMW0Q+var+ZiL0lZV9LszSTtC1Qd84at2vMLtrZcX2h1hh26CWxpSgSKLiyDvp7H j4IpmHt71/hcsQQ8WILL5oZpVh2w/Pz12kQQ/zuRRt6a1yWmqrolFhuR4HNxVBa4AQj5 S6Tw== X-Gm-Message-State: APjAAAVFxTI44kG0eXbXBH4kpJsqbqRqO14yaZXhyffTAvAUOeATSI58 VzcRQ9A5NA8RYVaqGzksB463uXABPWr3Cr7y3xo= X-Received: by 2002:a6b:7a09:: with SMTP id h9mr1900505iom.266.1556924046853; Fri, 03 May 2019 15:54:06 -0700 (PDT) MIME-Version: 1.0 References: <20190503033440.cow6xm4p4hezgkxv@linux-r8p5> <20190503034205.12121-1-deepa.kernel@gmail.com> <20190503195148.t6hj4ly3axqosse3@linux-r8p5> In-Reply-To: <20190503195148.t6hj4ly3axqosse3@linux-r8p5> From: Deepa Dinamani Date: Fri, 3 May 2019 15:53:42 -0700 Message-ID: Subject: Re: [PATCH] signal: Adjust error codes according to restore_user_sigmask() To: Davidlohr Bueso , Thomas Gleixner Cc: Linux Kernel Mailing List , Alexander Viro , Eric Wong , Omar Kilani , Jason Baron , Arnd Bergmann , Linux FS-devel Mailing List , Andrew Morton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The original patch was merged through the tip tree. Adding tglx just in case. I will post the revised patch to everyone on this thread. > >For all the syscalls that receive a sigmask from the userland, > >the user sigmask is to be in effect through the syscall execution. > >At the end of syscall, sigmask of the current process is restored > >to what it was before the switch over to user sigmask. > >But, for this to be true in practice, the sigmask should be restored > >only at the the point we change the saved_sigmask. Anything before > >that loses signals. And, anything after is just pointless as the > >signal is already lost by restoring the sigmask. > > > >The issue was detected because of a regression caused by 854a6ed56839a. > >The patch moved the signal_pending() check closer to restoring of the > >user sigmask. But, it failed to update the error code accordingly. > > > >Detailed issue discussion permalink: > >https://lore.kernel.org/linux-fsdevel/20190427093319.sgicqik2oqkez3wk@dcvr/ > > > >Note that the patch returns interrupted errors (EINTR, ERESTARTNOHAND, > >etc) only when there is no other error. If there is a signal and an error > >like EINVAL, the syscalls return -EINVAL rather than the interrupted > >error codes. > > Thanks for doing this; I've reviewed the epoll bits (along with the overall > idea) and it seems like a sane alternative to reverting the offending patch. Sorry maybe the description wasn't clear. What I actually am saying is that all these syscalls were dropping signals before and 854a6ed56839a4 actually did things right by making sure they did not do so. But, there was a bug in that it did not communicate to userspace when the error code was not already set. However, we could still argue that the check and flipping of the mask isn't atomic and there is still a way this can theoretically happen. But, this will also mean that these syscalls will slow down further. But, they are already expected to be slow so maybe it doesn't matter. I will note this down in the commit text. I don't think reverting was an alternative. 854a6ed56839a4 exposed a bug that was already there. > Feel free to add: > > Reviewed-by: Davidlohr Bueso > > A small nit, I think we should be a bit more verbose about the return semantics > of restore_user_sigmask()... see at the end. > > > > >Reported-by: Eric Wong > >Fixes: 854a6ed56839a40f6b5d02a2962f48841482eec4 ("signal: Add restore_user_sigmask()") > >Signed-off-by: Deepa Dinamani > >--- a/kernel/signal.c > >+++ b/kernel/signal.c > >@@ -2845,15 +2845,16 @@ EXPORT_SYMBOL(set_compat_user_sigmask); > > * usigmask: sigmask passed in from userland. > > * sigsaved: saved sigmask when the syscall started and changed the sigmask to > > * usigmask. > >+ * returns 1 in case a pending signal is detected. > > How about: > > " > Callers must carefully coordinate between signal_pending() checks between the > actual system call and restore_user_sigmask() - for which a new pending signal > may come in between calls and therefore must consider this for returning a proper > error code. > > Returns 1 in case a signal pending is detected, otherwise 0. Ok, I will add more verbiage here. Thanks, Deepa