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=-2.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 C443FC433E0 for ; Sat, 4 Jul 2020 02:47:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 04F30206BE for ; Sat, 4 Jul 2020 02:47:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mykernel.net header.i=cgxu519@mykernel.net header.b="Fm9afagj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04F30206BE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mykernel.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3FB408D0018; Fri, 3 Jul 2020 22:47:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AB0E8D0001; Fri, 3 Jul 2020 22:47:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C0A18D0018; Fri, 3 Jul 2020 22:47:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 130A58D0001 for ; Fri, 3 Jul 2020 22:47:13 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6A968824556B for ; Sat, 4 Jul 2020 02:47:12 +0000 (UTC) X-FDA: 76998856704.10.cord86_46120c526e97 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 43B6616A0D2 for ; Sat, 4 Jul 2020 02:47:12 +0000 (UTC) X-HE-Tag: cord86_46120c526e97 X-Filterd-Recvd-Size: 5272 Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Sat, 4 Jul 2020 02:47:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1593830685; cv=none; d=zoho.com.cn; s=zohoarc; b=i5KJUdoyhT0TAgplZhoNKHF+YRCEkB+BAIpt320uXBRG2BMbQBRNZ02rIxOxHv1MCWZX+Ari0QTkKthIrxKDO1kHGeNyPFYf85WWqNQQkxOQqgM9YTzh8lJN2m04zwxB6RCt++QXKdu2dFksFYy1aa64amvsKR3C2ZgPkkK1lbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1593830685; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=R28qiqXO1ZK8rRzTmz2LjViwPmvijxc8ExZKsIzPoIQ=; b=Zq4jzicWBdLO1EnrBGeGzIfCTN03+YaYIkcUrvawLMokzbD1s1H6w9fEBTlfXTejJN584za1Fnx/KuGRQHC1CXwrjRE8nFYikSlqtDx+yGhMa2GicJfDlhKu/jlP2EJuxDXI93wX6McWf8aQrs5fi4Dd66JuJRHi2cJeRgitoWY= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=mykernel.net; spf=pass smtp.mailfrom=cgxu519@mykernel.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1593830685; s=zohomail; d=mykernel.net; i=cgxu519@mykernel.net; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=R28qiqXO1ZK8rRzTmz2LjViwPmvijxc8ExZKsIzPoIQ=; b=Fm9afagjsbot7/WsVPD9uqcr1YhGIepxiwp/N7KZzwlbzu8Nbd95suO72BCtel+a YuoDBVFb0opBNaM/BrFMa/qcvq4y+sf2RDHQfGpkuYhlbRNOHJpAJuJG3LHvmIwF5+b MuUByFuuAbJecKPLUP5W2NhqqfsT+Soi40u6wtp0= Received: from [172.16.132.209] (183.237.64.250 [183.237.64.250]) by mx.zoho.com.cn with SMTPS id 1593830683851759.3156519969666; Sat, 4 Jul 2020 10:44:43 +0800 (CST) Subject: Re: [PATCH] mm/shmem: fix freeing new_attr in shmem_initxattrs() To: Hugh Dickins Cc: Andrew Morton , Daniel Xu , linux-mm@kvack.org References: <20200703065636.20897-1-cgxu519@mykernel.net> <20200703122043.c931cf9e0c85878ccc4e53f1@linux-foundation.org> <72d2c8fd-9f07-a48c-cb92-f3f0ba2f26b4@mykernel.net> From: cgxu Message-ID: <6859bdf0-6c65-f2a0-77b4-b827aa729b88@mykernel.net> Date: Sat, 4 Jul 2020 10:44:40 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-ZohoCNMailClient: External X-Rspamd-Queue-Id: 43B6616A0D2 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 7/4/20 10:20 AM, Hugh Dickins wrote: > On Sat, 4 Jul 2020, cgxu wrote: >> On 7/4/20 4:15 AM, Hugh Dickins wrote: >>> On Fri, 3 Jul 2020, Andrew Morton wrote: >>>> On Fri, 3 Jul 2020 14:56:36 +0800 Chengguang Xu >>>> wrote: >>>> >>>>> new_attr is allocated with kvmalloc() so should be freed >>>>> with kvfree(). >>>>> >>>>> ... >>>>> >>>>> --- a/mm/shmem.c >>>>> +++ b/mm/shmem.c >>>>> @@ -3178,7 +3178,7 @@ static int shmem_initxattrs(struct inode *inode, >>>>> new_xattr->name = kmalloc(XATTR_SECURITY_PREFIX_LEN + >>>>> len, >>>>> GFP_KERNEL); >>>>> if (!new_xattr->name) { >>>>> - kfree(new_xattr); >>>>> + kvfree(new_xattr); >>>>> return -ENOMEM; >>>>> } >>>> Indeed. Maybe simple_xattr_alloc() should have been called >>>> simple_xattr_kvmalloc(). >>> That would give a better hint, true. But it's been simple_xattr_alloc() >>> for a while, and "alloc" doesn't claim "kmalloc" or "__get_free_page" >>> or whatever, so its new users ought to check, and its old users ought >>> to be updated when a change is made. >>> >>> This is a >>> Fixes: fdc85222d58e ("kernfs: kvmalloc xattr value instead of kmalloc") >>> Cc: stable@vger.kernel.org # v5.7 >>> >>> (Though I hope the restricted use of xattrs on tmpfs cannot actually >>> get into multi-page allocations.) >>> >>> It's a good catch, Chengguang, thank you: but isn't your patch >>> incomplete? It looks like this omission goes beyond mm/shmem: >>> include/linux/xattr.h contains a simple_xattrs_free(), used by >>> both shmem and kernfs, which also says "kfree(xattr)" still. >>> >>> Please extend and re-subject and re-Cc your fix to cover that >>> too (and check nothing else has been missed) - thanks. >> Thanks for pointing that out, I overlooked that part. Since this patch >> has already merged to Andrew's tree, I would like to make another >> patch to handle rest of the fixing and that probably can go into >> vfs-tree or others. > So it has. Well, I'd prefer you to make one patch for all the fallout, > sent to Andrew, Cc'ed to the people Cc'ed on fdc85222d58e and me; then > Andrew will drop mm-shmem-fix-freeing-new_attr-in-shmem_initxattrs.patch > in favor of the new patch - which will be fixing more of mm/shmem too > (it calls the buggy inline function). But if you or Andrew disagree, > no problem, better to fix it piece by piece than not at all! That's also fine for me, let me send v2 that includes all of the fixing. Thanks, cgxu