From patchwork Thu Mar 14 21:04:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10853599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0596E1515 for ; Thu, 14 Mar 2019 21:04:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E264F2988B for ; Thu, 14 Mar 2019 21:04:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C37F429DEC; Thu, 14 Mar 2019 21:04:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 541D229DEC for ; Thu, 14 Mar 2019 21:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbfCNVEo (ORCPT ); Thu, 14 Mar 2019 17:04:44 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50348 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbfCNVEo (ORCPT ); Thu, 14 Mar 2019 17:04:44 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2EKwhw3102507; Thu, 14 Mar 2019 21:04:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=9KPBiGvUZVixIRVgF2LvW0yiPvbdeR2i06Z+SATxAQ4=; b=tRgqr1zXbll5Hj7FLshYEYULkx1DE1q5vFFtuIqUFRU7fTkAmaIicUJ4LFzgz4LpTlH3 0S3CpQ0nkJJlNvH4315mwOSxe7K3uKvF4Q4eNqBLSTzpty/ET6qr6NTFMS7dPrDsUwAq cqcgYOC8uMwSgN9S9LJGMcI3pwHN5KqwZng7NPlPwsUnYBoyoMl4BogPHmVRJ6wp3Atu s0cGir0Eedj+ow5+wafRNw7W1v1nZHiyv2QKIATTOcnGaCaOdkjqISoaKIJ8OWUl+RUL Qn6nRTYQG4ImQSq8KYj+VMroQimv09/JgdNqWJZRG9ocpKJSW03Qg6dLKxCJtakZlmWp 1w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2r464ruede-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Mar 2019 21:04:39 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x2EL4Xu1015850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Mar 2019 21:04:33 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2EL4XuU006597; Thu, 14 Mar 2019 21:04:33 GMT Received: from localhost (/10.145.178.102) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Mar 2019 21:04:33 +0000 Subject: [PATCH 07/36] xfs_io: actually check copy file range helper return values From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Anna Schumaker , Christoph Hellwig Date: Thu, 14 Mar 2019 14:04:26 -0700 Message-ID: <155259746648.31886.15984241616376190830.stgit@magnolia> In-Reply-To: <155259742281.31886.17157720770696604377.stgit@magnolia> References: <155259742281.31886.17157720770696604377.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9195 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903140143 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong We need to check the return value of copy_src_filesize and copy_dst_truncate because either could return -1 due to fstat/ftruncate failure. Fixes: 628e112afdd98c5 ("xfs_io: implement 'copy_range' command") Signed-off-by: Darrick J. Wong Reviewed-by: Anna Schumaker Reviewed-by: Christoph Hellwig --- io/copy_file_range.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/io/copy_file_range.c b/io/copy_file_range.c index 4e2969c9..d069e5bb 100644 --- a/io/copy_file_range.c +++ b/io/copy_file_range.c @@ -120,11 +120,24 @@ copy_range_f(int argc, char **argv) return 0; if (src == 0 && dst == 0 && len == 0) { - len = copy_src_filesize(fd); - copy_dst_truncate(); + off64_t sz; + + sz = copy_src_filesize(fd); + if (sz < 0 || (unsigned long long)sz > SIZE_MAX) { + ret = 1; + goto out; + } + len = sz; + + ret = copy_dst_truncate(); + if (ret < 0) { + ret = 1; + goto out; + } } ret = copy_file_range_cmd(fd, &src, &dst, len); +out: close(fd); return ret; }