Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3472440imu; Sun, 11 Nov 2018 15:54:11 -0800 (PST) X-Google-Smtp-Source: AJdET5cvgqjctnPdbkNxO8zzGpPiym0X+ZCpgcBGCEUPy3y+ObzpYC1e+FeH4nCEoP3jPdZ/i+UR X-Received: by 2002:a17:902:2ac3:: with SMTP id j61-v6mr17752920plb.139.1541980451009; Sun, 11 Nov 2018 15:54:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980450; cv=none; d=google.com; s=arc-20160816; b=rsB5L31L5vS31E+L52c9Ce684Lr1ZX5FkZOfg3gHSgxU+/sQ50M0D87uaichelCag8 EOodGpUcMo+IqTQAsukn56k+Q5ks3BBDLDpYj5J1dbFtDA5o9hp1lkeHGSn4oTsFlNMj tlVgy24btbxsevWsDEy9mVwv2CTuOyw9fo4LyZU55UyqoMCSCTMptTqwI8Or+rNuuqlE nfQIQ/kcvy0NgnIusTwn44VPLRLxKQwEnHPEYva9gNdKoPD0oWpJeaA7k7zGo7E9v+H/ pQ+4DJ8M8yEgMvOXxCdQP/bCcusyuqUAVewAmUIxUf/u+JcXTd64hLWMzL2IiTXIuPpE aZZw== 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:dkim-signature; bh=HAGNAEsAG6g4SPCrZGVJeSMwDyw+kJ8FaUUf8mFyHME=; b=QsoRQkRBtpq3cXvTn0I1plU8DVXXBRJqRHsdSc4+jW2luzKy/sMevwthvXI8hyRICg LpPmbSnHtON3yJptXYCsxjfgR6TbjcrleJB7r9dqtD9FAoGAK99WbC3qFeqxY+hSQwJ2 6juUBQZ95rF2yHjs8dCIKOC5eolIybdTEve1y8Iga6HfabUpQUPZgkMa8oY5ycRCnJc/ bl5ygY+/1xwHGbjPllkFaa23XoB5RJ0F0/WYudHdsY+TOpJf/s+cBiTRYRWhkuxQE/3j GmH71xKN7HLGzUlqaBWOo90KFA+3F+WYwkQYMefxbOLNMgntxaxGq9MhYdzoEGQ2WoSJ wqnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="G/IaSuFI"; 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 u11-v6si14689606pgh.55.2018.11.11.15.53.55; Sun, 11 Nov 2018 15:54:10 -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=@kernel.org header.s=default header.b="G/IaSuFI"; 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 S1733185AbeKLJn5 (ORCPT + 99 others); Mon, 12 Nov 2018 04:43:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:37584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732772AbeKLISZ (ORCPT ); Mon, 12 Nov 2018 03:18:25 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 93C91223C8; Sun, 11 Nov 2018 22:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975308; bh=QvcDQzhI8A2/jmo+CR28PtPOoxprpg8HPU7GlMGA430=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G/IaSuFIhavH15RPbvmXXQQTY8Lv9hwA/v2gJtP3/R+4jEE7by15VGPWPk4CZ6HJZ 5sbQAoKHJjd3tE+9clf7bnpNHj+moOR2mfRA9F2OV4gAv6cq5/x2yADW01gS7k6PFu b0tDpXgQl+9iKTRS70W9lT8lGgONZX5qraSj2WDc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Andrea Arcangeli , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 249/361] userfaultfd: disable irqs when taking the waitqueue lock Date: Sun, 11 Nov 2018 14:19:56 -0800 Message-Id: <20181111221653.034748085@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christoph Hellwig commit ae62c16e105a869524afcf8a07ee85c5ae5d0479 upstream. userfaultfd contains howe-grown locking of the waitqueue lock, and does not disable interrupts. This relies on the fact that no one else takes it from interrupt context and violates an invariat of the normal waitqueue locking scheme. With aio poll it is easy to trigger other locks that disable interrupts (or are called from interrupt context). Link: http://lkml.kernel.org/r/20181018154101.18750-1-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Andrea Arcangeli Reviewed-by: Andrew Morton Cc: [4.19.x] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/userfaultfd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1026,7 +1026,7 @@ static ssize_t userfaultfd_ctx_read(stru struct userfaultfd_ctx *fork_nctx = NULL; /* always take the fd_wqh lock before the fault_pending_wqh lock */ - spin_lock(&ctx->fd_wqh.lock); + spin_lock_irq(&ctx->fd_wqh.lock); __add_wait_queue(&ctx->fd_wqh, &wait); for (;;) { set_current_state(TASK_INTERRUPTIBLE); @@ -1112,13 +1112,13 @@ static ssize_t userfaultfd_ctx_read(stru ret = -EAGAIN; break; } - spin_unlock(&ctx->fd_wqh.lock); + spin_unlock_irq(&ctx->fd_wqh.lock); schedule(); - spin_lock(&ctx->fd_wqh.lock); + spin_lock_irq(&ctx->fd_wqh.lock); } __remove_wait_queue(&ctx->fd_wqh, &wait); __set_current_state(TASK_RUNNING); - spin_unlock(&ctx->fd_wqh.lock); + spin_unlock_irq(&ctx->fd_wqh.lock); if (!ret && msg->event == UFFD_EVENT_FORK) { ret = resolve_userfault_fork(ctx, fork_nctx, msg);