Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp228284ybt; Tue, 23 Jun 2020 20:25:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6MBHuOttRoC+DiljkjenLvkB+xZnkk/YeWEQZIxxVfF9lGZq+rWhYG5V8ReWaP81PiT7Y X-Received: by 2002:a17:906:57c6:: with SMTP id u6mr219118ejr.194.1592969146280; Tue, 23 Jun 2020 20:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592969146; cv=none; d=google.com; s=arc-20160816; b=q1vSl/CIFVlAQCgpZRf4ClH3D4aoJN48Ggi3xYGzvnjLgSEkR3RSNgGuWwrrZpEFVM ndXWObyn1hbr+Pg7MLa2GNHG0rUwayTq2ks2paMEpayb+aea45i0Ajv4vhpupDU3wnFi jyoxMLBb/dDGj+WHFK9H3TBKdas2H425j1RAqZZ1zQ3U0wbXPbYyDm2bboYrNKafha46 /VmuRE0E3ZvAMiyxgGl9J6VdigPzV3Qvc5dUGEt1Fy+TWIirJbWK3c2kJl0dWKgAe07H DxfeJIC5ywK+px/YuUjv1UawauPQhiqyY/7eyH34x8m1Rw7tKCNJgTR6Kv3gfX5rJ+FN 4eTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ukvtydvO6v/huANXwXMEUQDQqt4nzrdZg8Ec18jLIfE=; b=qcuI+F3WE2EivpBsik4owHtAT5qGsKklZ5hHZItRGerEELFpbmIWeL2Dcx6K+rYfwN nNb4JPp55KSngtyI1ZaAum8+Gi0kfHzb2DSx6oqevGQjWd1WGDXKCwf51xKE6SctCcrD SAacZZp7QGehq6hba8gZHAdKXhvrCyc+ysbvgwSK13Aeu60Tjx6kIIvhnARyYjy4LN/v 3JKah+iklR2/56Q9T1ZYieshiQd6uKVD+alYTIZocrfcRoTNbV3/GjkPkY3sZQ5ove51 aJzzenKACV08pALtBh8z+7o8tCQf0Dc8CKqOQX/eze4mQBU5Z6jofTkD8eTM1GdiMA2i CeWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=TgT8Q6jQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f6si13497686edv.356.2020.06.23.20.25.23; Tue, 23 Jun 2020 20:25:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=TgT8Q6jQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388663AbgFXDZH (ORCPT + 99 others); Tue, 23 Jun 2020 23:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388526AbgFXDZH (ORCPT ); Tue, 23 Jun 2020 23:25:07 -0400 Received: from casper.infradead.org (unknown [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC71CC061573; Tue, 23 Jun 2020 20:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ukvtydvO6v/huANXwXMEUQDQqt4nzrdZg8Ec18jLIfE=; b=TgT8Q6jQceWJZID30HBOuDzxJ8 QWDsnC6gRO62PUd7otmn0RY+xm2nbLlvm0CREPLjuaB20ZdJjnPAe3lSnnwplNy8Nb2KwpNxVasiC rGDqzpf3sftJt/jYtTgNUjsb9EcX2r4kP7NtQ3+CedIk0ZeTtDla+HA1r3hjJXIfNf6Qe4lqJPn7v 2Gl+O2+6fac2LmKPmCH0keVj1KusM5Yun2DMgA0vjNyHhUvc5hZ7UtBEKgmBe736wAMOeW4GqNXsm MD/TTwpOjLRKAYprwKNFDZjaempyiTK0sfxQ91hyav+JU3t184qArBwXpK/v7LcOVZNALIpXhF1vS FyYGGoYw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnw1n-0007sL-Gi; Wed, 24 Jun 2020 03:24:47 +0000 Date: Wed, 24 Jun 2020 04:24:47 +0100 From: Matthew Wilcox To: Peng Fan Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li , Tiezhu Yang Subject: Re: [PATCH] fs/read_write.c: Fix memory leak in read_write.c Message-ID: <20200624032447.GK21350@casper.infradead.org> References: <1592968023-20383-1-git-send-email-fanpeng@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1592968023-20383-1-git-send-email-fanpeng@loongson.cn> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 24, 2020 at 11:07:03AM +0800, Peng Fan wrote: > kmemleak report: > unreferenced object 0x98000002bb591d00 (size 256): > comm "ftest03", pid 24778, jiffies 4301603810 (age 490.665s) > hex dump (first 32 bytes): > 00 01 04 20 01 00 00 00 80 00 00 00 00 00 00 00 ... ............ > f0 02 04 20 01 00 00 00 80 00 00 00 00 00 00 00 ... ............ > backtrace: > [<0000000050b162cb>] __kmalloc+0x234/0x438 > [<00000000491da9c7>] rw_copy_check_uvector+0x1ac/0x1f0 > [<00000000b0dddb43>] import_iovec+0x50/0xe8 > [<00000000ae843d73>] vfs_readv+0x50/0xb0 > [<00000000c7216b06>] do_readv+0x80/0x160 > [<00000000cad79c3f>] syscall_common+0x34/0x58 > > This is because "iov" allocated by kmalloc() is not destroyed. Under normal > circumstances, "ret_pointer" should be equal to "iov". But if the previous > statements fails to execute, and the allocation is successful, then the > block of memory will not be released, because it is necessary to > determine whether they are equal. So we need to change the order. This patch doesn't make sense. It will _introduce_ a memory leak, not fix one.