From patchwork Tue May 12 19:43:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 11543839 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B27E92A for ; Tue, 12 May 2020 19:43:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F21D920731 for ; Tue, 12 May 2020 19:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589312597; bh=pRktm8hjZa1savK3NLDlMFCn9q2as+Ud+LDXutVl3TE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xTpyAcQOPB0t7+DxRGHDbn90PjTb6sevBDb1bhjLwUIcw4umOOcRsY/DBcnc8S7JJ D3U0ubsPfZOlFY0W9NzZYiid+Qtsw1k+Afr9vigLfdExbMtJ+lpsUvY6zgEAUrrlZH UH3s+HK/iDgj+5zgrQcPnroSz2p+ubiMZR8GqkP4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731072AbgELTnP (ORCPT ); Tue, 12 May 2020 15:43:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731042AbgELTnL (ORCPT ); Tue, 12 May 2020 15:43:11 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60471C061A0E for ; Tue, 12 May 2020 12:43:10 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id k6so15456684iob.3 for ; Tue, 12 May 2020 12:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qDftBJHTSVWUMGmOVvO/pH+pahE34h/2CLqQbMrb1kQ=; b=VzOhyBJ50rj9y88lIuva7HYzzznyCm0H+hG7FD00dWc/TiDJCA0E+1yzh9jKD03Cfi kSccnBPJ+dd0SV6w5izzhPQuEkkxsawS6RQRRTCRL1INujJo/0rcYEQ2llTEpm97/DVq mEJYM55GogDCJuBTiXAFQQf9lmZRzfKSyTmK4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qDftBJHTSVWUMGmOVvO/pH+pahE34h/2CLqQbMrb1kQ=; b=bkZlL39CONG4KwgTxHoiQjYqiM4mbMa4VVj1te1e27HSYpRS17QtWAK0+WQg9C3u/n s4FCDjNKznyhravnC0lgjiP/Yg3nSykHVfC+HrHUN7+l9ocKBlbyHCcCI6qV1EflyQyy +tUttwuovqTLbONPluaZoc26ZrBU845K9fLx49aqQyiiyvu8RDlM8wklT4CH4PcVXKcR ZQaHyGuALPefluwfYOMbo9JiQ5nRTOm5DcqXMlbRXwjTqLz44UHs4iMJ1zeq2RFEMf4l Ef8GIwFz3C0FrLBeck74oJMl4vUnwhBKwxye5wV5p/jTR7E+lPRJA5FlurgqPvtWUwUV Cgnw== X-Gm-Message-State: AGi0Pub+5696FZxWTAHaQSYkocQ1dgHuXND/wsJONi8hJCpf6v0QukGD zx123x4ss7XSJ2NTupULbvDDWQ== X-Google-Smtp-Source: APiQypIsGCeZQw29/QluF60afoXeCbOYKr29SjbfKMLdQ5jsD5GwNaMMwLiS2ovQFxknpVAAqHt+kg== X-Received: by 2002:a02:a1c8:: with SMTP id o8mr9897803jah.38.1589312589835; Tue, 12 May 2020 12:43:09 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f5sm6177781iok.4.2020.05.12.12.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 12:43:09 -0700 (PDT) From: Shuah Khan To: viro@zeniv.linux.org.uk, axboe@kernel.dk, zohar@linux.vnet.ibm.com, mcgrof@kernel.org, keescook@chromium.org Cc: Shuah Khan , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] fs: avoid fdput() after failed fdget() in ksys_sync_file_range() Date: Tue, 12 May 2020 13:43:04 -0600 Message-Id: <71cc3966f60f884924f9dff8875ed478e858dca1.1589311577.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix ksys_sync_file_range() to avoid fdput() after a failed fdget(). fdput() doesn't do fput() on this file since FDPUT_FPUT isn't set in fd.flags. Change it anyway since failed fdget() doesn't require a fdput(). Refine the code path a bit for it to read more clearly. Reference: commit 22f96b3808c1 ("fs: add sync_file_range() helper") Signed-off-by: Shuah Khan --- fs/sync.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/sync.c b/fs/sync.c index 4d1ff010bc5a..300ca73ec87c 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -364,15 +364,15 @@ int sync_file_range(struct file *file, loff_t offset, loff_t nbytes, int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags) { - int ret; - struct fd f; + int ret = -EBADF; + struct fd f = fdget(fd); - ret = -EBADF; - f = fdget(fd); - if (f.file) - ret = sync_file_range(f.file, offset, nbytes, flags); + if (!f.file) + goto out; + ret = sync_file_range(f.file, offset, nbytes, flags); fdput(f); +out: return ret; } From patchwork Tue May 12 19:43:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 11543841 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1621D92A for ; Tue, 12 May 2020 19:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFAD220747 for ; Tue, 12 May 2020 19:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589312599; bh=beE77q25hW/1loatIJdzB1aoxh+2mFYu7Ra5+rAp95o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1tUEjneMm1Jq/psZihWxwaHMqYw9CNxPty2IOVvG5rxIBPiMBzmysvavMkbZ4CB0l Rf6FznhmzrxRYUz5B5zxGOeXFGTLTOjTpVt/Wiszu+hguJeuWfvikt4rbc8pRusub2 bigH2PLFmnFI5RMJTyzir4HahH4bUCv96tIceovw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731067AbgELTnP (ORCPT ); Tue, 12 May 2020 15:43:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731045AbgELTnL (ORCPT ); Tue, 12 May 2020 15:43:11 -0400 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA8CC061A0C for ; Tue, 12 May 2020 12:43:11 -0700 (PDT) Received: by mail-il1-x143.google.com with SMTP id n11so13638786ilj.4 for ; Tue, 12 May 2020 12:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5f4RJYDHuVh6PmC6voPvbMaVVDseoYYhjdA/uiY/cuE=; b=dDiHF6QcMxQj56/4jqPt4rp/TqSru+DYb5YBX3ju2WcjAsD10UHXWv9eb12IepmgEW HSipt/qwzbvnX8XXGO4VQkcFHihJfgqksvGWHtpRW7GbV7Y96UrZ/KWBoGTMTyx51U7S HfvA/sHFw2IKN+p76Lc+RXjMrhy5RLIJulFb4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5f4RJYDHuVh6PmC6voPvbMaVVDseoYYhjdA/uiY/cuE=; b=D4oU5ezCmgccYi4K/IM0V70m+Tp/UE7s7chtgzifDzc8OG/U9aqfTlUyqyPSatFPYL ahz0p7YGyi/jSnUyVdh7L74OfEEAioDYb67vR04AHzJmjMy9Gz6//fDU6sdSUeaQBCMS ch0nV67ZcgRjj5eYIE5792U3H8JtqmpBwsBTzPaRFP1ZOdMLM85cnjkt07WJkyFgca6h 2lRzHJ3J/RWuHeQjWfvpvbW0QrfocffMxYkbcS5Z3NCvGQtimXXs+njJzOumtoIBpQiE C78WZLR5m4W6GzIeJGt7tKcF/H3KrKHXSQ/V8uhJUDTNpeKqACP+qbUWSOILdFy1f0uA KsGw== X-Gm-Message-State: AGi0PubgtcoMIXL+osD/vy/sILGxw59Dq9RvwwNJxHI9jqTv7WqCDazN rJhjxGhOHhVFoJC7vy1oUTThPw== X-Google-Smtp-Source: APiQypIV9anjY93T29+evCtA4VrmEbcf4OSTA50DnDtX7FtsaM8yY0lwTkE+9nA9jpVE3b3YvOfPVA== X-Received: by 2002:a05:6e02:c74:: with SMTP id f20mr23535878ilj.86.1589312590842; Tue, 12 May 2020 12:43:10 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f5sm6177781iok.4.2020.05.12.12.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 12:43:10 -0700 (PDT) From: Shuah Khan To: viro@zeniv.linux.org.uk, axboe@kernel.dk, zohar@linux.vnet.ibm.com, mcgrof@kernel.org, keescook@chromium.org Cc: Shuah Khan , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] fs: avoid fdput() after failed fdget() in kernel_read_file_from_fd() Date: Tue, 12 May 2020 13:43:05 -0600 Message-Id: <1159d74f88d100521c568037327ebc8ec7ffc6ef.1589311577.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix kernel_read_file_from_fd() to avoid fdput() after a failed fdget(). fdput() doesn't do fput() on this file since FDPUT_FPUT isn't set in fd.flags. Fix it anyway since failed fdget() doesn't require a fdput(). This was introduced in a commit that added kernel_read_file_from_fd() as a wrapper for the VFS common kernel_read_file(). Fixes: b844f0ecbc56 ("vfs: define kernel_copy_file_from_fd()") Signed-off-by: Shuah Khan --- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index 06b4c550af5d..ea24bdce939d 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1021,8 +1021,8 @@ int kernel_read_file_from_fd(int fd, void **buf, loff_t *size, loff_t max_size, goto out; ret = kernel_read_file(f.file, buf, size, max_size, id); -out: fdput(f); +out: return ret; } EXPORT_SYMBOL_GPL(kernel_read_file_from_fd);