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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 8AB07C432C3 for ; Tue, 26 Nov 2019 13:17:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6543420836 for ; Tue, 26 Nov 2019 13:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728257AbfKZNRJ (ORCPT ); Tue, 26 Nov 2019 08:17:09 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7172 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728047AbfKZNRJ (ORCPT ); Tue, 26 Nov 2019 08:17:09 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 81B80EC6394053749B91; Tue, 26 Nov 2019 21:17:04 +0800 (CST) Received: from localhost.localdomain (10.175.124.28) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Tue, 26 Nov 2019 21:16:53 +0800 From: Zhang Xiaoxu To: , , Subject: [PATCH v2] posix_acl: fix memleak when set posix acl. Date: Tue, 26 Nov 2019 21:38:09 +0800 Message-ID: <20191126133809.2082-1-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.17.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When set posix acl, it maybe call posix_acl_update_mode in some filesystem, eg. ext4. It may set acl to NULL, so, we can't free the acl which allocated in posix_acl_xattr_set. Use an temp value to store the acl address for posix_acl_release. Signed-off-by: Zhang Xiaoxu --- fs/posix_acl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/posix_acl.c b/fs/posix_acl.c index 84ad1c90d535..0a359d06274c 100644 --- a/fs/posix_acl.c +++ b/fs/posix_acl.c @@ -882,7 +882,7 @@ posix_acl_xattr_set(const struct xattr_handler *handler, const char *name, const void *value, size_t size, int flags) { - struct posix_acl *acl = NULL; + struct posix_acl *acl = NULL, *p = NULL; int ret; if (value) { @@ -890,8 +890,15 @@ posix_acl_xattr_set(const struct xattr_handler *handler, if (IS_ERR(acl)) return PTR_ERR(acl); } + + /* + * when call set_posix_acl, posix_acl_update_mode may set acl + * to NULL,use temporary variables p for posix_acl_release. + */ + p = acl; ret = set_posix_acl(inode, handler->flags, acl); - posix_acl_release(acl); + + posix_acl_release(p); return ret; } -- 2.17.2