Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp264442imu; Mon, 19 Nov 2018 22:07:20 -0800 (PST) X-Google-Smtp-Source: AJdET5cqXyHpvbip/+BIT+k/tU9KwxPXWwZSOnPZmAMAVfRyySvN8aNOcIoLjnFvvq4Bfj10M7vi X-Received: by 2002:a62:160c:: with SMTP id 12-v6mr854169pfw.45.1542694040905; Mon, 19 Nov 2018 22:07:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542694040; cv=none; d=google.com; s=arc-20160816; b=rUpp2Asd693Yhq/hU3bX5iHNtqtDGqtWmn/AaOxjBXuuCEZBTGwNPZA1kyUwu+fNAb L8PGPcP5S35LNUo6Vh+NLLLeG56bFV5hrWClgOTRg369qIIUeXSdIgqLocBvnmrV79kM OC1zPILxgIzIA1gGwq4QhVIGwFBOyxPOqSI24peVhFNMfhnQz/FUVrHvWf0SIVtBECLR NLssdU4ZovB4XOMlRLP2YuR1GgnYBuoqG3dK8JUR2bH5nb18qhILh4wwHrrC0+6LEWna XqEKzhjvYjr5pH68oeCFTnUU5liwnIJ9lq58Xtl2THIjrl2+Xhy72TfNUw986Zj/x/uI EcQw== 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=aGiaCMTlIf1ChSKXNPut5X3cyUNnLU37C2uDQXkCI/E=; b=nUFUg612Fh+8AaljejQGpDTCeUTFDr5+IymDxP9BXFopp89F0DuuXR8hZJ8Yu8mPVp +0QLKc9RQrA6nol4yg++vG4S3x8tTZuDrG0Nx/v1XPhBSFQ1Owgbm0uiJW5b1EDiqtuQ QkHb5bhfvloBRlWaTCkM/siWADrTVbXwcIEDa4p6mpF4gX1Umcxl7/T1Si/6D9n5YJxm dHfSpsoy8f8BEXRum0K9VxjIhjkCVL14XSZSQMrZUAFAYP6b2Wb3uH5VRrSvhwgnxO++ HUq1jFnGr8tCsCrGn+R4zaC7x84RSEqotUdu/MEHPEOjm5tL6w77rI43Tp0GYtK3M1ZX JWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FbV91fBW; 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 g83si19138377pfb.278.2018.11.19.22.07.06; Mon, 19 Nov 2018 22:07:20 -0800 (PST) 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=FbV91fBW; 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 S1731267AbeKTQdp (ORCPT + 99 others); Tue, 20 Nov 2018 11:33:45 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36954 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbeKTQdp (ORCPT ); Tue, 20 Nov 2018 11:33:45 -0500 Received: by mail-pg1-f194.google.com with SMTP id 80so422754pge.4 for ; Mon, 19 Nov 2018 22:06:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=aGiaCMTlIf1ChSKXNPut5X3cyUNnLU37C2uDQXkCI/E=; b=FbV91fBWHIobGIuGl3rKvP1IenOWUrUpXMw6xhdKaNBncJ46KFMMld3hM97DvcIFsu r7/KaFl9fUmTFfx2ltSw0fTUOEtJJETQfiC7TMJTCVg9wFXaoLllV1460lgjbdgj1Srf 59Pi4wMsqptesRELdEjhjeUAKbn2ZUgwkyPPkvgRCUEbuDK/Ti8AKLt16rsye6CGp6ML 7cjPJeIjoODlRpHzxYtgizYSDWcA6n6jEqiN+VuFIAXRmL8iJ6jm2/8xTdWPl3M6xIjL NVwxBsQFEmo1WSRAXXQbRHen7EB16u/SYkL1gKiU7lxfv/CYbd0AE3Mee1ceobabXXp7 FygA== 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=aGiaCMTlIf1ChSKXNPut5X3cyUNnLU37C2uDQXkCI/E=; b=lqCUQrevpJ5xInmHh9dvCOoPFJBOaZoScc22cGMLHnK4A6WrsYoiuAHG7WjiGI7sgj nb5IgTvzn0nDHuBZbmdTvfIGPiceG7fPhP2kB2+I/RFBCv6wjN7Y3uHA7rWKgJWWaqf2 h12Y5sullI4gdB3zXbffVlCByiliTR+SPiAA5B0NUAKZXk09AuDr1thKDrWROrWCjY+z tyRrGKX6jIanK00cXXiy+71IMUy7RJf/P+Kv+r1etR2ZpGsFplpMtKv9lRr8FDIBCGiB Dw2PeYhvD/pcsQ7CVvKQtLcFhgdEOga/hc4vRFpjqndR4xlqCjivmaH8iDZTxLeoFV5s 9rvQ== X-Gm-Message-State: AA+aEWa7y43Dxb64nswi3sO7ykiZ1vCXHTlOyZdHcNFGDT1KO1KVsBcb c8+5eNE8Jl7xfpJ/T/umwdQ= X-Received: by 2002:a63:d157:: with SMTP id c23mr749804pgj.170.1542693982267; Mon, 19 Nov 2018 22:06:22 -0800 (PST) Received: from localhost.localdomain (c-73-140-212-29.hsd1.wa.comcast.net. [73.140.212.29]) by smtp.gmail.com with ESMTPSA id u186sm16141245pgd.62.2018.11.19.22.06.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 22:06:21 -0800 (PST) From: Andrei Vagin To: Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Andrei Vagin , "Eric W. Biederman" , Andrew Morton Subject: [PATCH] ptrace: take into account saved_sigmask in PTRACE_{GET,SET}SIGMASK Date: Mon, 19 Nov 2018 22:06:16 -0800 Message-Id: <20181120060616.6043-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. Cc: Oleg Nesterov Cc: "Eric W. Biederman" Cc: Andrew Morton Fixes: 29000caecbe8 ("ptrace: add ability to get/set signal-blocked mask") Signed-off-by: Andrei Vagin --- 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 1be35729c2c5..660d78c9af6c 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -417,10 +417,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); @@ -438,6 +448,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; @@ -446,6 +460,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 21fec73d45d4..fc0d667f5792 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include /* * Access another process' address space via ptrace. @@ -925,18 +926,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; @@ -962,6 +971,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.17.2