From patchwork Wed Mar 20 19:36:08 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: 10862529 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 3BB8117E9 for ; Wed, 20 Mar 2019 19:36:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E31128EB1 for ; Wed, 20 Mar 2019 19:36:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1301829E79; Wed, 20 Mar 2019 19:36:11 +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 B483B29E7A for ; Wed, 20 Mar 2019 19:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726123AbfCTTgK (ORCPT ); Wed, 20 Mar 2019 15:36:10 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:49770 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726115AbfCTTgK (ORCPT ); Wed, 20 Mar 2019 15:36:10 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2KJXwvi116892; Wed, 20 Mar 2019 19:36:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=iokh9A77+xtshpBK9zkXh70Kd0j9EQx7f5b7rZWCp6Y=; b=Ea0486MLwvL3OOIkY0ODeL9ux9RPrxnc8A7cJsgxaMWIPYZmvRs7+/4k41RjajyUk/iE XJ9utaJmaVnLulzHBdWEp2DMOZNozRAft+EfM5JX1wfCoZVid7Jk0/gGLhDgcylHzLBP HoPTInbvb2LaB21P7RXpgEE5htLC04po4lsPsZhxiDwjpkSBKcOXhpHeOrGe+XOeqAFI ieI1om6mEwoRM5LXM3vltBOMDfcM1UNKvg9bR8SLLquSwusENvs/XMdhyhl01qpoJ8ym 9I8UBiJDM6oel/3js4hG0YdmoeH8Mcr5TsJWtuZ2kQOQyFr7U+tyFZEpsY0ETqbFFJMH xw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2r8rjuvwba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Mar 2019 19:36:08 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2KJa7m9028966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Mar 2019 19:36:07 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2KJa78Y001165; Wed, 20 Mar 2019 19:36:07 GMT Received: from localhost (/10.159.247.212) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 20 Mar 2019 12:36:07 -0700 Date: Wed, 20 Mar 2019 12:36:08 -0700 From: "Darrick J. Wong" To: sandeen@sandeen.net Cc: linux-xfs@vger.kernel.org Subject: [PATCH 40/36] xfs_io: fix label parsing and validation Message-ID: <20190320193608.GD1183@magnolia> References: <155259742281.31886.17157720770696604377.stgit@magnolia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <155259742281.31886.17157720770696604377.stgit@magnolia> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9201 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 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-1903200142 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 When we're trying to set a new label, check the length to make sure we won't overflow the label size, and size label[] so that we can use strncpy without static checker complaints. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Reviewed-by: Eric Sandeen --- io/label.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/io/label.c b/io/label.c index 602ece89..72e07964 100644 --- a/io/label.c +++ b/io/label.c @@ -40,7 +40,7 @@ label_f( { int c; int error; - char label[FSLABEL_MAX]; + char label[FSLABEL_MAX + 1]; if (argc == 1) { memset(label, 0, sizeof(label)); @@ -54,7 +54,13 @@ label_f( label[0] = '\0'; break; case 's': - strncpy(label, optarg, sizeof(label)); + if (strlen(optarg) > FSLABEL_MAX) { + errno = EINVAL; + error = 1; + goto out; + } + strncpy(label, optarg, sizeof(label) - 1); + label[sizeof(label) - 1] = 0; break; default: return command_usage(&label_cmd);