Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1653531img; Tue, 19 Mar 2019 12:22:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqycRUecXBe/3r+0xKGgP5TOwAktv6ZUuLTy5mCJlgAa28qwkGNShvssz3W5V2/44XGmWL3s X-Received: by 2002:a17:902:7e0f:: with SMTP id b15mr3628113plm.124.1553023348076; Tue, 19 Mar 2019 12:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553023348; cv=none; d=google.com; s=arc-20160816; b=hV2INEQOznRmjO9cJb2jcjX9BTOMLeOJNIYKxGgZg/bBilDc2hG6CJTD/VUnwtJH6l rNX+RJNl4y6Hm5x31U8pj3uw69edSjZL/umeDu2edOLlAOa9U1MnZkdJOz2ejpUJ978d hQJhbLqMC6IU2C9rZOba3bQBdyV+Q2cVT7cBpF7aKITd9mDLeXjXvr5wS0AN+UiIg21V KhEIULKuaMgM36WHgxbxswfNs53ayTCamYJTM3tPaEfde6EjwdqqvXKHbabHeuG8e+we skkYVq5wGrmpRQW4HKGz7j8q/40oVPPQrHJA12N/iC6h4RVZjM1jlRJmpErQ8iuvmlUG K1ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=zX2I+WV09MAFoKOGvG5BuE+Ojt8cSFDVe53iWCQGyyc=; b=yp5TWpQRfQodwiBtexzilXhGbSzoY6iTMI8AEVCABiYKT2lZD0PuCETBjHZYNPCJig 29H0sXTB3UqYjBCDrbCyzCN8A6HO56rI5G+QJ5Kp5cyCNRPrwX3u97OFc8edeDs5rSRL 2Jqg7H+DF5cYChopuer20gsp3WGWUSxb6BcgN0kg8Vmam92/oihfEAO+EncAxS73AJiQ lJD3ShMEmdikDy5X39b7uBQEIFKz7hfyXvMihhPGXRqFP43iccNWJfjVQvXgV/YjOMHF Mc5p4zOJlPdxct/G2+Yh7RhNePnnBNGd+bVdr6nbKeyXvezDoaLgLhi/GpWI08NNSL3a 3bRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NwDmI29k; 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 v5si11609720pgr.489.2019.03.19.12.22.12; Tue, 19 Mar 2019 12:22:28 -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=NwDmI29k; 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 S1727194AbfCSTUQ (ORCPT + 99 others); Tue, 19 Mar 2019 15:20:16 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38993 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbfCSTUP (ORCPT ); Tue, 19 Mar 2019 15:20:15 -0400 Received: by mail-pg1-f194.google.com with SMTP id h8so14519573pgp.6 for ; Tue, 19 Mar 2019 12:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=zX2I+WV09MAFoKOGvG5BuE+Ojt8cSFDVe53iWCQGyyc=; b=NwDmI29kK9iW19gKo3QaQ6ZTpqYSpnWlVTw/TenE+Rt9dvGOxsftotPNd2JNZqp4Eo Wl+NOH+ayhWBBCXtPFp7rfcg8xMRQS1iGDtNtlSW2d7OcvFE0FUD82PcKnnr45px2MS7 SInLyxw1N/IQuG+oIat04PNJpw+pDNfIEu/uhlYP0z87J3IMawZxN1X8cnTj0rL6T63I R+au7hV8FcNoYDJrFkhJWlcNIwpPwBQ3SfhmMOOc1FOC+CQEJ3bhw8Kuhj1JGr18jp+L c6suk7Jc6uddRAHaBmBd8yCZ1rc46tv7ofCT/Mcpz0vhraNmP2mysQYAXe3QHjUV5CAO xMSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zX2I+WV09MAFoKOGvG5BuE+Ojt8cSFDVe53iWCQGyyc=; b=b740SJyytkvkhv4z5em6f/yzQ8fcUDaEoHsXEJplZO3vC+aU1fGFHezQfI4hsZQPoP OOmt3O/ohuSUVArA9zw155Xw+czrezLfm3Yd1/ZZp74lSniAyyMspozVS6EFR5JDRTQA OP0+aA06wS84q0EXNvqrpyMZqPQClC/bith7104U/j6RaE6HAhfgH1irq8Fv2GOcWeIU WhBFZSGxpOp4l2cldQ0Z0c1k4aYbq5WB5qIiL9uk7bQOrl1XNjGq3WtsTuZYsL4vfli5 AOkzNY091rYtYgUlo1CWDXi4WAhgOxdPGyl29X0u+N1lBNcFwXPIW/8MBAShTq4q21+N nQBw== X-Gm-Message-State: APjAAAW3s04jC8CqAGwIbhLqSywHgEPaTxrJIx4Pb7Haf9wWjDDxEPrX ZA68Z3bPoSotncfCUL79KRk= X-Received: by 2002:a17:902:8ec1:: with SMTP id x1mr27627035plo.52.1553023214574; Tue, 19 Mar 2019 12:20:14 -0700 (PDT) Received: from localhost.localdomain ([2620:0:1008:fd00:ed8e:8493:d2b7:8f54]) by smtp.gmail.com with ESMTPSA id s4sm9350698pgp.89.2019.03.19.12.20.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Mar 2019 12:20:13 -0700 (PDT) From: Andrei Vagin To: Andrew Morton , Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Andrei Vagin , "Eric W. Biederman" , Stephen Rothwell Subject: [RESEND PATCH] ptrace: take into account saved_sigmask in PTRACE_{GET,SET}SIGMASK Date: Tue, 19 Mar 2019 12:19:57 -0700 Message-Id: <20190319191957.27156-1-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are a few system calls (pselect, ppoll, etc) which replace a task sigmask while they are running in a kernel-space When a task calls one of these syscalls, the kernel saves a current sigmask in task->saved_sigmask and sets a syscall sigmask. On syscall-exit-stop, ptrace traps a task before restoring the saved_sigmask, so PTRACE_GETSIGMASK returns the syscall sigmask and PTRACE_SETSIGMASK does nothing, because its sigmask is replaced by saved_sigmask, when the task returns to user-space. This patch fixes this problem. PTRACE_GET_SIGMASK returns saved_sigmask is it's set. PTRACE_SETSIGMASK drops the TIF_RESTORE_SIGMASK flag. Link: http://lkml.kernel.org/r/20181120060616.6043-1-avagin@gmail.com Fixes: 29000caecbe8 ("ptrace: add ability to get/set signal-blocked mask") Signed-off-by: Andrei Vagin Cc: Oleg Nesterov Cc: "Eric W. Biederman" Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell --- Hello Andrew, This patch is in a queue for a long time and it looks like you are waiting ack from Oleg. He said the patch is fine: https://www.spinics.net/lists/kernel/msg2972154.html And promised to send a formal ack in reply to this email. include/linux/sched/signal.h | 18 ++++++++++++++++++ kernel/ptrace.c | 15 +++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index ae5655197698..e412c092c1e8 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -418,10 +418,20 @@ static inline void set_restore_sigmask(void) set_thread_flag(TIF_RESTORE_SIGMASK); WARN_ON(!test_thread_flag(TIF_SIGPENDING)); } + +static inline void clear_tsk_restore_sigmask(struct task_struct *tsk) +{ + clear_tsk_thread_flag(tsk, TIF_RESTORE_SIGMASK); +} + static inline void clear_restore_sigmask(void) { clear_thread_flag(TIF_RESTORE_SIGMASK); } +static inline bool test_tsk_restore_sigmask(struct task_struct *tsk) +{ + return test_tsk_thread_flag(tsk, TIF_RESTORE_SIGMASK); +} static inline bool test_restore_sigmask(void) { return test_thread_flag(TIF_RESTORE_SIGMASK); @@ -439,6 +449,10 @@ static inline void set_restore_sigmask(void) current->restore_sigmask = true; WARN_ON(!test_thread_flag(TIF_SIGPENDING)); } +static inline void clear_tsk_restore_sigmask(struct task_struct *tsk) +{ + tsk->restore_sigmask = false; +} static inline void clear_restore_sigmask(void) { current->restore_sigmask = false; @@ -447,6 +461,10 @@ static inline bool test_restore_sigmask(void) { return current->restore_sigmask; } +static inline bool test_tsk_restore_sigmask(struct task_struct *tsk) +{ + return tsk->restore_sigmask; +} static inline bool test_and_clear_restore_sigmask(void) { if (!current->restore_sigmask) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 771e93f9c43f..6f357f4fc859 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include /* * Access another process' address space via ptrace. @@ -924,18 +925,26 @@ int ptrace_request(struct task_struct *child, long request, ret = ptrace_setsiginfo(child, &siginfo); break; - case PTRACE_GETSIGMASK: + case PTRACE_GETSIGMASK: { + sigset_t *mask; + if (addr != sizeof(sigset_t)) { ret = -EINVAL; break; } - if (copy_to_user(datavp, &child->blocked, sizeof(sigset_t))) + if (test_tsk_restore_sigmask(child)) + mask = &child->saved_sigmask; + else + mask = &child->blocked; + + if (copy_to_user(datavp, mask, sizeof(sigset_t))) ret = -EFAULT; else ret = 0; break; + } case PTRACE_SETSIGMASK: { sigset_t new_set; @@ -961,6 +970,8 @@ int ptrace_request(struct task_struct *child, long request, child->blocked = new_set; spin_unlock_irq(&child->sighand->siglock); + clear_tsk_restore_sigmask(child); + ret = 0; break; } -- 2.20.1