From patchwork Thu May 7 23:57:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 11535139 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 006691668 for ; Thu, 7 May 2020 23:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D80FC20CC7 for ; Thu, 7 May 2020 23:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588895852; bh=8qfQLw31FShD88rQMGySezZ3vGjAxDMEECPZlWfb3eU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FL/ssMfXS9eG5M8qmRkHt0bHJH8bKSFRdOaa8/ZtZRIktvJ7gpYdm4l2US3T8mU1g MJIqxrV7n2KRkDOV4frUxGXrk7LToNyeqOZXmHFkjVFXX4OuhkXym9ljsvgAKVKhXE Mdcwp478PQanbMH8wqsYptOKbmohIpkyGW8pYfnE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbgEGX5c (ORCPT ); Thu, 7 May 2020 19:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727072AbgEGX5R (ORCPT ); Thu, 7 May 2020 19:57:17 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B83EC05BD09 for ; Thu, 7 May 2020 16:57:16 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id c18so7042251ile.5 for ; Thu, 07 May 2020 16:57:16 -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=9TwK4u8Oz+hIVdTAgPTDuNePQX/j9l3iXT78dNtrMzA=; b=GSWVCbnYftAggwrWtoofsSVg5KaUUx2c+wWZgyeyBk1u+bCb7nxD9dpZldsclYDu5C nX1TB/LfcQ2XeDdI0qzxstB5mqAimi/zyMyP3HLAMdDhpbNd/70j/59+8IbGuIx9uN8x mxnl8V6RelTgjF2xQzdPohrldstjbm0beUwI8= 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=9TwK4u8Oz+hIVdTAgPTDuNePQX/j9l3iXT78dNtrMzA=; b=YnzkeVhgxYWW4Dgpvfnrnx5jw9nskVuXrrj/r4Wz8p41qkIpoeKOov7+b4A51Qknwo R7daHIg491qGpGYa7A2mnQ3dJ4J6xQtSDs7MMv42ku/crEtxvQdcUrVRExYk3aHcGrgv OvK3jrCjPPeX/XURSHc0THGWn31fUOFhovt2QMeycP2yR0WhGw8b+yKg93mwp2TdUNWN v82Pa4zNpbIVssqsdWc5/OAP4hNrmUwuha/uTsqF1gETArTkGgm2q4ElbYOoO1Qtccbu tG3RdSwuF1amw8TILs+SDlcPCV7quksd+im/fPhNLdpZa811F5MMc5/CP/ktLK8RJKF1 8hqg== X-Gm-Message-State: AGi0PuarAYwwS4ehESkBEnAoFTzvS/cZ3w3CdJa8WhR/up8lQDyrJ7tW lLWeOUithhLofTGDAIV6NQBmFA== X-Google-Smtp-Source: APiQypJBM1xuTwXEsrDaqEq1u3eTWKXejiZiCER3XjowknHOSmHpGwOENdMMt20RM9A8e6EAv2euKA== X-Received: by 2002:a92:607:: with SMTP id x7mr15916103ilg.218.1588895835927; Thu, 07 May 2020 16:57:15 -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 f19sm1369893ioc.9.2020.05.07.16.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 16:57:15 -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 1/2] fs: avoid fdput() after failed fdget() in ksys_sync_file_range() Date: Thu, 7 May 2020 17:57:09 -0600 Message-Id: <31be6e0896eba59c06eb9d3d137b214f7220cc53.1588894359.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.20.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. Fix it anyway since failed fdget() doesn't require a fdput(). This was introdcued in a commit to add sync_file_range() helper. Fixes: 22f96b3808c1 ("fs: add sync_file_range() helper") Signed-off-by: Shuah Khan --- fs/sync.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/sync.c b/fs/sync.c index 4d1ff010bc5a..faaff835ef12 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -369,10 +369,11 @@ int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes, ret = -EBADF; f = fdget(fd); - if (f.file) + if (f.file) { ret = sync_file_range(f.file, offset, nbytes, flags); + fdput(f); + } - fdput(f); return ret; } From patchwork Thu May 7 23:57:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 11535137 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 3C58292A for ; Thu, 7 May 2020 23:57:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2458220CC7 for ; Thu, 7 May 2020 23:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588895840; bh=PDyygbnoFMpW7tBzZiOkHHNlA1bCTf+Cdlqi+WhL6QY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=l0eng8UOyN8VnvbrmYl9bLlgWApB04DlkYTX5gr1wKR8PbKlcK0QGUhXUKStpfWCK MRbKrp7oLFCCHuOc3iEdWf6koxDV9s5pgAWnWcFbCvQj+HR1LlnoOPlhUbhlVSoWff MyTuAUAhE8HskfsHDHHgqtrTdR1sUl5+N47c382M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbgEGX5T (ORCPT ); Thu, 7 May 2020 19:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727083AbgEGX5S (ORCPT ); Thu, 7 May 2020 19:57:18 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17AC7C05BD0A for ; Thu, 7 May 2020 16:57:18 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id m5so2630061ilj.10 for ; Thu, 07 May 2020 16:57:18 -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=8YERqo/O0CpgSp6GICUF3/1ifgurCUdYJLrnvIdN1x8=; b=SYWQJ+YCPO+1BQsW1dytD0nYU7twT//urz+z/iwpvLCo7DTZxbH8ItmxKrLc9qdYKg vchJc/AR5zkgXz7tVhtJgTzpxm3klLYK11xHodMifgBsaH9S2RBP9RiaBDbJae5INVSy GhkdUNocSR4HsxMBxvtyK/CQR/j60P9DzTuD4= 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=8YERqo/O0CpgSp6GICUF3/1ifgurCUdYJLrnvIdN1x8=; b=QrgFb1AJ8uZceTa6o8vduOvFX+RwlcMAKpZhzhdt5tWEtUT2gLFW+zaKDeYD4GQS8K ohubSrh38ziCI266eYl4bciA5w55T45kPg9N5x3J2BJF5nIjVOYAMLd72xDnZoknPN9E H9nOZWiaaC2iKisI/HgHo8980DCHGTnQFaC0ei0YAaeorpaf1n3OdHwiuIU5vvBjFiuR 394w8DyG4LIOcQAHwSghpbDVlWP9YOSwKuCAEGwl9tqq0Ygjyh7TLRu9Tr4uWi1vU6ox 5esLooVRpQHCPIwvZcQC5lgTiAr7btMeIsgmGKkFLJoMVPgt4iDR0WFTkrI9AUMpPGLL QELQ== X-Gm-Message-State: AGi0PuY7Rhn6lkfeJTMQZAvf26kVRNG9lOE1GLYuG6wqXCa1p44RJvwZ Bv+2vKyl4qyiF12CK5mprIKXSA== X-Google-Smtp-Source: APiQypKqHlNwMSQC9E2pjfwDU94VGlthfw04mg7vAiNxP1abahKSR5sOWkaEYm0byD44ICMxpXsFSw== X-Received: by 2002:a92:d801:: with SMTP id y1mr17212948ilm.308.1588895837458; Thu, 07 May 2020 16:57:17 -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 f19sm1369893ioc.9.2020.05.07.16.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 16:57:17 -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 2/2] fs: avoid fdput() after failed fdget() in kernel_read_file_from_fd() Date: Thu, 7 May 2020 17:57:10 -0600 Message-Id: <8b2cec548ea7f3b156038873b37bc24084a689ad.1588894359.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.20.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);