Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1369502pxx; Fri, 30 Oct 2020 08:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAqBp/s//GEE4IkOvc5M/PXSCbvBvn+p050YcagVXFFtZ4VpfLXXavuWSDmA5osD3lrRwE X-Received: by 2002:a50:a6d0:: with SMTP id f16mr2872487edc.135.1604071699621; Fri, 30 Oct 2020 08:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604071699; cv=none; d=google.com; s=arc-20160816; b=Q/AGocSZkxn3dgPuEIEuyYEXhObiLXdYFO9v3chAqyN/5LIc2D3PjKhmE2DCYCovK/ hxXzayKjY+zyCt4GJniJ4fvxRwhpkmy+nE2VYjgbwuvzhXgH5RkH17ZOQNyux/52EgcH 2BIqI85udZY8ncDDopP9VLhwU+5VSKAK53/Ka0qVeabn4ThxbvXJuwLd/ffgvxCCl+SH +wG0JpXpICV7nIppSMUy8cjf5ZpQNhN+1xIVf9xIKoOPW/zwreH7z8XGxJPWJjx7uriV cFMaHIqXm0VAVOvi0B92V/QuwBOLyUwo5tdpXJ9Sa9Srm7MaY55cZGAAOAZ5qvfAOu/w e28w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QwLkawJq9ox4OkwlI6rcfvvTwI6YSYml8hrmWz5QMs4=; b=M5dLaOhjKBXjZRT29nVImF+pALK3Bj+65HE4Ex/tChPolV1VSNKDUDivH6XT9FDDBx rhUW2FpwldaraZVMgPr7hX1WLko3v5iJcZC4SI2VBg0VtMqbjGckcPdRspTDYnrQxR54 LX3bZx4tMvqF943kHx0K0+IVqua+vnsIXu7iU9J5EnTnDnwngGg4rM2spmXS42HUv/L1 S20XBj+mVTIOyrdWq7HGYdXhX5ex+MKSadSjZSjGJnpDdExd8RELsTRBbU1hTUKsfHEE uuMFeFoHrhIa4uwNd/puLIhkibb8RCIcY4iJuVAIIqCe5AGWOAb4ixIp1JDDuYz47wlp ZL4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LVYMPioj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz2si3830753ejc.558.2020.10.30.08.27.56; Fri, 30 Oct 2020 08:28:19 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LVYMPioj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbgJ3PY1 (ORCPT + 99 others); Fri, 30 Oct 2020 11:24:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58156 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725844AbgJ3PY1 (ORCPT ); Fri, 30 Oct 2020 11:24:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604071466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=QwLkawJq9ox4OkwlI6rcfvvTwI6YSYml8hrmWz5QMs4=; b=LVYMPiojJTt3fBy+catAdG48iCQxvxVD4aYt5kdmhP6vUmVT5xc2fWPb8WGJ9bjMFm7wEc HvEA7yCVcHqqK7PgSOSpvlj1sGcEc12+ulyGlhue3hpgkHdl1LxwghXfBtJVX8ODItmkkM DitbvoGqCFVt/A33WWAcE9iBjuwWtM0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-KjTXOrOBOp6_ImkjQbGxcg-1; Fri, 30 Oct 2020 11:24:22 -0400 X-MC-Unique: KjTXOrOBOp6_ImkjQbGxcg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B6A58F62E8; Fri, 30 Oct 2020 15:24:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-66-212.rdu2.redhat.com [10.10.66.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D231109F192; Fri, 30 Oct 2020 15:24:17 +0000 (UTC) From: Qian Cai To: Jens Axboe Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next] fs: Fix memory leaks in do_renameat2() error paths Date: Fri, 30 Oct 2020 11:24:07 -0400 Message-Id: <20201030152407.43598-1-cai@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We will need to call putname() before do_renameat2() returning -EINVAL to avoid memory leaks. Fixes: 3c5499fa56f5 ("fs: make do_renameat2() take struct filename") Signed-off-by: Qian Cai --- fs/namei.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 27f5a4e025fd..9dc5e1b139c9 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4362,11 +4362,11 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd, int error; if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) - return -EINVAL; + goto out; if ((flags & (RENAME_NOREPLACE | RENAME_WHITEOUT)) && (flags & RENAME_EXCHANGE)) - return -EINVAL; + goto out; if (flags & RENAME_EXCHANGE) target_flags = 0; @@ -4486,6 +4486,14 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd, } exit: return error; +out: + if (!IS_ERR(oldname)) + putname(oldname); + + if (!IS_ERR(newname)) + putname(newname); + + return -EINVAL; } SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname, -- 2.28.0