From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A799FC606C1 for ; Mon, 8 Jul 2019 15:36:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F9F021743 for ; Mon, 8 Jul 2019 15:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600189; bh=ek20vikqeNTdh8UyIHg+luSl1BDDdZIm/V5dgx82/oE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=q+Bm4sRE+xLrP3C1tEK5lKrxvNdJug/NGSuvlmMV3LD37sw4YJSgSxERmfffYYlMl sRitObft5lRvqjmpNeioESlrJpSSTgWAeHEznEs239UWAFcVxXuki2NT+qAu7dm0/O fKun0ioxUvrHXifIRVlSvC+tbxYprluWNDDlUDsM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390428AbfGHPdp (ORCPT ); Mon, 8 Jul 2019 11:33:45 -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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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);