Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7151285ybi; Mon, 8 Jul 2019 15:40:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhwcaZpFHg1Sa0B2t8kjtyV32zZRJ1YZ7eqk1y1ne7uod4arSbP5QuKykQvE1BWWSJe/pU X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr28552265pju.63.1562625645384; Mon, 08 Jul 2019 15:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625645; cv=none; d=google.com; s=arc-20160816; b=sW4JVIffpdHYuEi6b+8IaJLbhlJ1PH10z7VC7cRvgyiaY36lNRHcGEY0P7g1EhrWH1 gbMCh+LIIr6J7cJoPgGLBiE15571znsG60XVVt9uNnbdezk52cB+KIy0yNwQnCrW79Ni ITcujVbQLlxh/amLWi7TkwxAGKQW+vWAx0g+j805XAKZB0kK2nfOU/K+dFkQbiLjFE9x XuQeCuJ3n5xb2an9Hfxw1RYy818+IaTF1S9I+Uc9PaGmZrJE2ps6/EPyBbvIUxDNEps/ dqdYAVREk/CiR+4aRLWSY0fejH6oi6ORlEQUpDtca2UJlWl7GF5Ptsmt/XKEXNA/DpFo 12fg== 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=4/rliw/eIWTxcw/l9q7537M7AQMZ2o7daG6GHHnLmy4=; b=uTAKuS2y9wt58V8N917l75MVH62f0PX3WuJ7PXVxbxjtGkLBAVU/4BKo+rwWBh52wS 9BcSjxzCnJ2beAN+g5C6CfS1gZ7zZtMX/eXawdBfHRBasD8q8cpToSWRuyNBF+8aIgpu zcZo5WdnVoPpqwc6gcb6DSZumVRA6jy78XpYayaLT11nne3e65B0mVjWpjY+lEDjyqvG kqtbbmZ1Zf9nefEZZrLrRK7qLxkGtZ6NvaYsgpzcKpBMCN0CdMv5TOWw0cVPj96RdNxx JD5BuOL3l6LWIuJKqbJf3dN3X984D5CMeGFRmNITPpg4IxYYhnAHAHAksC41XKCNU23J IOWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YoJ3+Jg0; 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 u191si19417761pgb.302.2019.07.08.15.40.26; Mon, 08 Jul 2019 15:40:45 -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=@kernel.org header.s=default header.b=YoJ3+Jg0; 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 S2390433AbfGHPdq (ORCPT + 99 others); Mon, 8 Jul 2019 11:33:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:35866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732876AbfGHPdm (ORCPT ); Mon, 8 Jul 2019 11:33:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1626520665; Mon, 8 Jul 2019 15:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600021; bh=ek20vikqeNTdh8UyIHg+luSl1BDDdZIm/V5dgx82/oE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YoJ3+Jg0UWPSBH5/33uR5EcJn6Kq0c8exzTpNkWrKF8gjmV7pFfRiM6EPw1HMSdMu qhiorZd4LynKXpvqoQah/kqCkRIKv58xGgec0xmZyElWiGdcDXzthIm7vWMMJKMQmS yBqPB4O1Slz+c8fzlKLmScrPD4rx+Dp9FDqMjVW0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleg Nesterov , Qian Cai , Hugh Dickins , Jens Axboe , Andrew Morton , Linus Torvalds Subject: [PATCH 5.1 68/96] swap_readpage(): avoid blk_wake_io_task() if !synchronous Date: Mon, 8 Jul 2019 17:13:40 +0200 Message-Id: <20190708150530.140084973@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150526.234572443@linuxfoundation.org> References: <20190708150526.234572443@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Oleg Nesterov commit 8751853091998cd31e9e5f1e8206280155af8921 upstream. swap_readpage() sets waiter = bio->bi_private even if synchronous = F, this means that the caller can get the spurious wakeup after return. This can be fatal if blk_wake_io_task() does set_current_state(TASK_RUNNING) after the caller does set_special_state(), in the worst case the kernel can crash in do_task_dead(). Link: http://lkml.kernel.org/r/20190704160301.GA5956@redhat.com Fixes: 0619317ff8baa2d ("block: add polled wakeup task helper") Signed-off-by: Oleg Nesterov Reported-by: Qian Cai Acked-by: Hugh Dickins Reviewed-by: Jens Axboe Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_io.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/mm/page_io.c +++ b/mm/page_io.c @@ -137,8 +137,10 @@ out: unlock_page(page); WRITE_ONCE(bio->bi_private, NULL); bio_put(bio); - blk_wake_io_task(waiter); - put_task_struct(waiter); + if (waiter) { + blk_wake_io_task(waiter); + put_task_struct(waiter); + } } int generic_swapfile_activate(struct swap_info_struct *sis, @@ -395,11 +397,12 @@ int swap_readpage(struct page *page, boo * Keep this task valid during swap readpage because the oom killer may * attempt to access it in the page fault retry time check. */ - get_task_struct(current); - bio->bi_private = current; bio_set_op_attrs(bio, REQ_OP_READ, 0); - if (synchronous) + if (synchronous) { bio->bi_opf |= REQ_HIPRI; + get_task_struct(current); + bio->bi_private = current; + } count_vm_event(PSWPIN); bio_get(bio); qc = submit_bio(bio);