Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp728378imm; Thu, 13 Sep 2018 06:56:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYvFpBJ6q/0fDqHtUAGlha7Tr09RRmikgXAzS0ZzcJFzHr6Jj8+e/u+X6Fiice1FHDjzRBV X-Received: by 2002:a17:902:6a83:: with SMTP id n3-v6mr7404355plk.246.1536846962490; Thu, 13 Sep 2018 06:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846962; cv=none; d=google.com; s=arc-20160816; b=Bf/iyxAip7CSGWM9gAbcebOFrtUEsUKGi8p1dXe+sgH84tSHAspFmVOxk+Mb9Zbgwh 5ZX3oCUccHkIjBXipYUAH61F8gec0BdojVB+C3LHTd8bsTvLWQonO+CtvGG2lj91yC+I htuR818bvF7+rbaVKfLW9bse6OPmZz/EXr6ykIX3LKLDuL/SXZXijKDtF2DqgpsUUHRi c4JM7y7uCOw5JvC3EW/C7WlD9gs0hJFuAS3HDYjMbxEDQHkVVME65ms1/8OIzXOuXOHk gnlI2a89CaRHg8EQb6zgMp5x+vrG9AZIoxqZnZy6MmAib6Vopul2GPnCEyRTBEoF+Axp CBmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=7v9WSU9aey7p0sTiVbTioxK3kOvSfh558sAdvR2U8/M=; b=IfBTH2sOJBW1I7tuIKnun4esR90//RKd7S19EWgtFeXCXsfYcxma3+L92wFyEt9tqe F/r/zXtkLvU3RQRMPL0gKJCmrCYJugnsJiQL+HvAc995xv8AhN7QE1mEEAv6Q85btBXR RgObJun34jrlu43LtnEtZ+A/vC/ceF20pMFtegGuvI4hz/4WEEKnxPThPmP6uQhWWn6W u4DqpyJ1OwdixYX9uks71x4DL6NsVX8SnW/sp6BSrDeEebR0c/SUyp8AbTNZ+31Di2gA oLS5H1tisSBL10nl/ziDkQW9ywuO/tEv5g4V47Ck9wDDuMUc09bUecjy7i4LJBuV4ciw BcRw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1-v6si3914470pfh.63.2018.09.13.06.55.46; Thu, 13 Sep 2018 06:56:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731265AbeIMTFP (ORCPT + 99 others); Thu, 13 Sep 2018 15:05:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34014 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731262AbeIMTFO (ORCPT ); Thu, 13 Sep 2018 15:05:14 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 039F6CE7; Thu, 13 Sep 2018 13:55:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Michal Hocko , Andrew Morton , Rik van Riel , "Peter Zijlstra (Intel)" , Kees Cook , Oleg Nesterov , Linus Torvalds , Sasha Levin Subject: [PATCH 4.18 041/197] fork: dont copy inconsistent signal handler state to child Date: Thu, 13 Sep 2018 15:29:50 +0200 Message-Id: <20180913131843.190222882@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn [ Upstream commit 06e62a46bbba20aa5286102016a04214bb446141 ] Before this change, if a multithreaded process forks while one of its threads is changing a signal handler using sigaction(), the memcpy() in copy_sighand() can race with the struct assignment in do_sigaction(). It isn't clear whether this can cause corruption of the userspace signal handler pointer, but it definitely can cause inconsistency between different fields of struct sigaction. Take the appropriate spinlock to avoid this. I have tested that this patch prevents inconsistency between sa_sigaction and sa_flags, which is possible before this patch. Link: http://lkml.kernel.org/r/20180702145108.73189-1-jannh@google.com Signed-off-by: Jann Horn Acked-by: Michal Hocko Reviewed-by: Andrew Morton Cc: Rik van Riel Cc: "Peter Zijlstra (Intel)" Cc: Kees Cook Cc: Oleg Nesterov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/fork.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1417,7 +1417,9 @@ static int copy_sighand(unsigned long cl return -ENOMEM; atomic_set(&sig->count, 1); + spin_lock_irq(¤t->sighand->siglock); memcpy(sig->action, current->sighand->action, sizeof(sig->action)); + spin_unlock_irq(¤t->sighand->siglock); return 0; }