Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5156535imu; Sun, 25 Nov 2018 17:59:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmjVwCWdGdDjXrf6pTliNh1azlOxRtnvE2y+bXKXI2Ims9Tc1xZTgpAexpf5dWCpjVmvCF X-Received: by 2002:a63:fe0a:: with SMTP id p10mr22605685pgh.265.1543197562326; Sun, 25 Nov 2018 17:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543197562; cv=none; d=google.com; s=arc-20160816; b=mH7yoRWTgG7jL3f7J6EmMai20y8yTSvQjs8ivBuDap951UndN8XThghA20h4PAlrax YNWMEqAwbzJA1e7C1BDGxGfAACeBszEThCjjkLi/3I2phEmNRNGArtE6BZVis+8omCdI J6Ox6hVn2AuZ7Nza+oLLm4Vk/lNUibAXnKVGHW8uTbIQE0ghMypzfiO9OFObskhVBo8k sRrSaTN0HzW9YH2qNNDZbsQhs5Zw59Hnrl6pBmY9lz/B0Atr4WgQQRYSx1qqMqGV7hQ+ wgelkcH3QYflf9i+oZelaf0xI6Ob8WbbdE/ndS2MOdpXGqaj3iNi9GTZDLR9xpnDDNHR 9P9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=buvgAOLwqloDZN9VvB9AgWN/CLf0MdCHRVAHlRRuGsI=; b=NrSvBoBMgjv9o+cUHOBQd0vh5oFiLGT18eFn9gqDJ4zo3jmAo19DEIIgRpXv4roo8S bs8NdaYeBaetUaAmfQyTR8VveFaZbgLhULgMPAFQVqIk6nFqAmW4YF7ZLj4sm8RM4WUc AlMsNDIpk2fgxiGuYE2Tytn0PA3NTJkzKXyDZHLdSJXDliVxDBlHw68dpnJPHErKGvW/ a1y8rIo/9yTKlShuhfzw7WyRb/rCeNhWAwdmTytPV1fp0Hax+c39Si412NEQ+68mDo59 HkHLi6vS3aUv6CsqiaNoL4NGjnkgLg5VtFfKCWgVA84Qkn86caV2IMSzQ/cOeFUXnTT5 wNtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=kPXTuxwz; 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 c136si20077008pfc.141.2018.11.25.17.59.05; Sun, 25 Nov 2018 17:59:22 -0800 (PST) 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=pass header.i=@163.com header.s=s110527 header.b=kPXTuxwz; 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 S1726154AbeKZMvC (ORCPT + 99 others); Mon, 26 Nov 2018 07:51:02 -0500 Received: from m12-14.163.com ([220.181.12.14]:45641 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKZMvC (ORCPT ); Mon, 26 Nov 2018 07:51:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=buvgAOLwqloDZN9VvB 9AgWN/CLf0MdCHRVAHlRRuGsI=; b=kPXTuxwzDntOWfqBCGfz3LhHGFyOauA+Av IU/iMPUHF3Pviap2/ixs9Yr/e5CgXWPWnAsSaIqkfWsHIsKf6ozQQeI0OCQNRwG9 SwievB5I+sqi//2IiALFwcADPezcfNifW4uIU2WPMZjpmGuAzZQOT2WSV1HlQbZz /xKlLWAqQ= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp10 (Coremail) with SMTP id DsCowACHXNU3U_tbwMqkBw--.49337S3; Mon, 26 Nov 2018 09:58:18 +0800 (CST) From: Pan Bian To: Ian Kent Cc: autofs@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] autofs: drop dentry reference only when it is never used Date: Mon, 26 Nov 2018 09:58:14 +0800 Message-Id: <1543197494-15688-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DsCowACHXNU3U_tbwMqkBw--.49337S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtr45tw4rCw43KF47WrW7urg_yoWDCrb_ua 1UurWxWrWrJr1Fya17GrWftFn3WryrJFW8Zw4Svr1agFy5KFnrW3s8Jas8urWDW347AFW5 Zr1qkr98CFy5ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0loGPUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiVBILclUMGKDOuwAAsr Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function autofs_expire_run calls dput(dentry) to drop the reference count of dentry. However, dentry is read via autofs_dentry_ino(dentry) after that. This may result in a use-free-bug. The patch drops the reference count of dentry only when it is never used. Signed-off-by: Pan Bian --- fs/autofs/expire.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/autofs/expire.c b/fs/autofs/expire.c index d441244..28d9c2b 100644 --- a/fs/autofs/expire.c +++ b/fs/autofs/expire.c @@ -596,7 +596,6 @@ int autofs_expire_run(struct super_block *sb, pkt.len = dentry->d_name.len; memcpy(pkt.name, dentry->d_name.name, pkt.len); pkt.name[pkt.len] = '\0'; - dput(dentry); if (copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire))) ret = -EFAULT; @@ -609,6 +608,8 @@ int autofs_expire_run(struct super_block *sb, complete_all(&ino->expire_complete); spin_unlock(&sbi->fs_lock); + dput(dentry); + return ret; } -- 2.7.4