From patchwork Fri Feb 1 20:03:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9B081390 for ; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABAF732C9E for ; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FE57330BE; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 498AD32C9E for ; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730292AbfBAUEY (ORCPT ); Fri, 1 Feb 2019 15:04:24 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40415 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729192AbfBAUEX (ORCPT ); Fri, 1 Feb 2019 15:04:23 -0500 Received: by mail-pg1-f194.google.com with SMTP id z10so3420722pgp.7 for ; Fri, 01 Feb 2019 12:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=NA6vvVyMDJPhQ9KgJXIJfBmv8U2CY45OLDLgFA0V5yM=; b=OuiYT/BaB9/iCTDObIpGDBZ/ANp5JmuAz7vm1DjNoRcbrHoeYePBTHtI+HTepSzym1 PJrL2Kyz5yeBRVEMF0bID7hrXFVAsZzcAB7Yino6yo/s/wICjsE0w21FfwJI/P4tZaJe zFnA4x4m9JqzTtiNtOKQplRip+YkV+ms4FeWdoGbKKxAIkyLCozWb1lKhfyp4809rn8i W3HOSXANky3qElmDCvHvKLuTR+mcJ4IWeTw8gG8P3qc8rQaZMsLW+D7mptbzIEp/+Xkx X1ukuDs3i/UyMSV0GdJqGGWBkgqMWnqdTitZsjIkEkSDlHFr9eE1wDtVE2IGAJgYUn4S 6oaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NA6vvVyMDJPhQ9KgJXIJfBmv8U2CY45OLDLgFA0V5yM=; b=Xh2n7MXokOIIe/TgbA1ETeqqJPBmoN9M6fGjoHkw8ujHGqYgjvAPAQtbc+mWHKGZCa fFSLJMi/P3PBtE5A/sMu+u5BskrAN3jS4iYHVbH7obc7JKvH3vE5UEJO6eHZAdEdAe1U P5ykmifMDkHHAZZ0KCVo6s5w0U/oYMEkVYs8bUMFFsS2tYRGLW/n1ptnV8MW2v19f95V S2zTYIr0E3/edGzWaGIKJKISIdeD7tJkt3M3GmXa8JSeh+NsreVCs5n6l5y6dvH6XM5t VMJ0mnNDiP5D61l2a6lm0HCW109lUb7PYBXuXjIYtAhI5tOwFX9feIZJsD9GwXJsnmmh oHrQ== X-Gm-Message-State: AJcUukcNLUFOMKdiAp/i4H9N1Jxxjw9uR4IF+pGgh4sEK5PQO8KNXSl7 jodJQKlPruN1/jc6KuBpJJcqedc= X-Google-Smtp-Source: ALg8bN4CPKP4yPRVdTv//6YlvAHXv+2ffsy/+LO9HkH2fucUzuRjRm9WVHsZ+Ak0NfORAYBAybH8TQ== X-Received: by 2002:a62:2781:: with SMTP id n123mr41311199pfn.138.1549051462535; Fri, 01 Feb 2019 12:04:22 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:21 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 01/23] CIFS: Fix possible oops and memory leaks in async IO Date: Fri, 1 Feb 2019 12:03:49 -0800 Message-Id: <1549051452-5968-2-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allocation of a page array for non-cached IO was separated from allocation of rdata and wdata structures and this introduced memory leaks and a possible null pointer dereference. This patch fixes these problems. Cc: Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/file.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 2c7689f..659ce1b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2696,6 +2696,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, rc = cifs_write_allocate_pages(wdata->pages, nr_pages); if (rc) { + kvfree(wdata->pages); kfree(wdata); add_credits_and_wake_if(server, credits, 0); break; @@ -2707,6 +2708,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, if (rc) { for (i = 0; i < nr_pages; i++) put_page(wdata->pages[i]); + kvfree(wdata->pages); kfree(wdata); add_credits_and_wake_if(server, credits, 0); break; @@ -3386,8 +3388,12 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, } rc = cifs_read_allocate_pages(rdata, npages); - if (rc) - goto error; + if (rc) { + kvfree(rdata->pages); + kfree(rdata); + add_credits_and_wake_if(server, credits, 0); + break; + } rdata->tailsz = PAGE_SIZE; } @@ -3407,7 +3413,6 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, if (!rdata->cfile->invalidHandle || !(rc = cifs_reopen_file(rdata->cfile, true))) rc = server->ops->async_readv(rdata); -error: if (rc) { add_credits_and_wake_if(server, rdata->credits, 0); kref_put(&rdata->refcount,