Received: by 10.192.165.148 with SMTP id m20csp1107360imm; Wed, 2 May 2018 14:18:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpDvqOF6rSCd98/Avkk7q4ti6ZB2HG2Wo92Gx+Dxmqh6nujAVakqY7kvULz5AluwD61hCo/ X-Received: by 2002:a17:902:3e5:: with SMTP id d92-v6mr22282653pld.104.1525295899448; Wed, 02 May 2018 14:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525295899; cv=none; d=google.com; s=arc-20160816; b=zV8M5xkbOiZSGLbIhbpQ65/DAafV43MqWziR5zLQlFceabrPCoC5jfMv13ZIIsjVJK +Gvoo1QrcCrZCwOhvIzQuLjHJRSmfNJzmovrIXRoaR5zREICUymwxHD9C7Zn5ojfoUP+ ODHrdHP5zuopkM3pXHhOVaAGU+55Q2tWC0IZ/YIXc6kVuL6fJlDP0rM8yU38sHrdNAPY IdyWsX/Cggw9z6MwVVUOxeAGe63C0Of7gUTiHDfs2ZkclRV/W5l4o8vyMeeTPF1L2w0K MfLitzx4/HDAMciqmHUaoeTvjf/1N0/MPlp5f2MmHpAfdxs2TXgS+Y5T8fp9GXdgYWA0 PCRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=H5Ouk3B5XIYL6R1tpa5B8eLFshnES5w3HpxilUrI3t8=; b=ly3lNMUf3CdcUbl4YgDfZUYJ6grTjP2TO7Huc9IYgHcUA0bkNi5/4N7lng9K2B6bFo NT9ka1MuhSHtvoJtycBnCOB8uM2PA7wr9iblQO6wmuud02k1AhLOcy2KWkCutAknBuK2 uU7+PWWEoJrD00/22G/31xfDy9FPnJYHDSkWE3Xt6GodLD7ml85AxLIAgYtvu9ni7/GV mFd3/fFVNCUlEJtxCAgRzQn4MQ/+6/6G8EOQVkc+7KL0StXZ9HwkpYyrWBtvqa+3peNA zqmO58t0Ye5lsqtqjk5qN/O8LYDbpBp70c9tJQEJ5FIICZPQQFSYOFyORVS+zuRWfD2o MHvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=c7n16Pmj; 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 94-v6si12461961plb.475.2018.05.02.14.18.05; Wed, 02 May 2018 14:18:19 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=c7n16Pmj; 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 S1751925AbeEBVQP (ORCPT + 99 others); Wed, 2 May 2018 17:16:15 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:37854 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751751AbeEBVPH (ORCPT ); Wed, 2 May 2018 17:15:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=H5Ouk3B5XIYL6R1tpa5B8eLFshnES5w3HpxilUrI3t8=; b=c7n16PmjusBhyyg1S4Zjfc4hB RWtCNuM6dHNDilbi5tPDD8qR5f0it76h8QvEUBaV/rEvJ9fzJnjrBfnBZ/oDY9q5jS1yiU1Rxnsdx rmVs8NDiCOBhzuQcv2A7qYBfWfO++R88jwkNGEErblpXz2TBqNSZJnPTs3KYI5LiSivtWSgfMpmox jlpOsEBB/ZnqXxwj8C0z5/sV/6/i//qvm0OZLMikTdexJbi5PZK+GVsr/dQe4xfUkIrcOLHUA1lAm UheJxFVnUPKh46jaxFB7bYOjcmpuVYuQjdyTPwjD33O51OEc/NrhnqXute2h0aizDycZ0YigWKe/c 2scSdvygQ==; Received: from 089144213252.atnat0022.highway.a1.net ([89.144.213.252] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fDz5d-0007Cq-EK; Wed, 02 May 2018 21:15:05 +0000 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] aio: sanitize ki_list handling Date: Wed, 2 May 2018 23:14:44 +0200 Message-Id: <20180502211448.18276-4-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180502211448.18276-1-hch@lst.de> References: <20180502211448.18276-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of handcoded non-null checks always initialize ki_list to an empty list and use list_empty / list_empty_careful on it. While we're at it also error out on a double call to kiocb_set_cancel_fn instead of ignoring it. Signed-off-by: Christoph Hellwig Acked-by: Jeff Moyer Reviewed-by: Greg Kroah-Hartman Reviewed-by: Darrick J. Wong --- fs/aio.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 7c1855afd723..18507743757a 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -553,13 +553,12 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel) struct kioctx *ctx = req->ki_ctx; unsigned long flags; - spin_lock_irqsave(&ctx->ctx_lock, flags); - - if (!req->ki_list.next) - list_add(&req->ki_list, &ctx->active_reqs); + if (WARN_ON_ONCE(!list_empty(&req->ki_list))) + return; + spin_lock_irqsave(&ctx->ctx_lock, flags); + list_add_tail(&req->ki_list, &ctx->active_reqs); req->ki_cancel = cancel; - spin_unlock_irqrestore(&ctx->ctx_lock, flags); } EXPORT_SYMBOL(kiocb_set_cancel_fn); @@ -1039,7 +1038,7 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx) goto out_put; percpu_ref_get(&ctx->reqs); - + INIT_LIST_HEAD(&req->ki_list); req->ki_ctx = ctx; return req; out_put: @@ -1107,7 +1106,7 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2) file_end_write(file); } - if (iocb->ki_list.next) { + if (!list_empty_careful(&iocb->ki_list)) { unsigned long flags; spin_lock_irqsave(&ctx->ctx_lock, flags); -- 2.17.0