From patchwork Thu Sep 26 18:42:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benny Halevy X-Patchwork-Id: 2950391 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8638BBFF0B for ; Thu, 26 Sep 2013 18:42:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B30B202E5 for ; Thu, 26 Sep 2013 18:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D38520164 for ; Thu, 26 Sep 2013 18:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754082Ab3IZSmJ (ORCPT ); Thu, 26 Sep 2013 14:42:09 -0400 Received: from mail-qa0-f46.google.com ([209.85.216.46]:61651 "EHLO mail-qa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753553Ab3IZSmI (ORCPT ); Thu, 26 Sep 2013 14:42:08 -0400 Received: by mail-qa0-f46.google.com with SMTP id j7so4637700qaq.12 for ; Thu, 26 Sep 2013 11:42:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=1MJEvkB0DsGyeN72pP2IW1U+4bno5ftj9v340K4p2to=; b=wrTAlbGFC8FZEJrCCT/gm4tNuCj0yVqd31CL9vEeg9o3M1ct0+X7O6dFRRmpckOtZQ Ir8d+GrEcPHJ23tmaBBSlYv2fiZROPGOA5OJbBfvzcLMwKbEvyf08z82dVYd0nS4moFu 7fUnYaDuUpkfDdj7qujrK/hjKgN+YEk6yBbGfxQGUNpc0PDZoprPTMqzAcqdb1dqUgbu PSRY31f3BqdKKnIDkDGCb27IfXoG8reZTY2ySbHLeNUR3Z0HmqpylZ4QCa5sgMGmlIOh o13MemhvyGj0/8NOtmEpJTHW6UYj0ojlqCA6UmvadgbwpoCmoelqkdN9rwPb/1FGWCmJ AKFw== X-Received: by 10.224.120.6 with SMTP id b6mr8722578qar.11.1380220927834; Thu, 26 Sep 2013 11:42:07 -0700 (PDT) Received: from bhalevy-lt.il.tonian.com.com (nat-pool-bos-u.redhat.com. [66.187.233.207]) by mx.google.com with ESMTPSA id y9sm10253735qaj.9.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 26 Sep 2013 11:42:07 -0700 (PDT) From: Benny Halevy To: " J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v0 33/49] pnfsd: Add IP address validation to nfsd4_set_pnfs_dlm_device() Date: Thu, 26 Sep 2013 14:42:05 -0400 Message-Id: <1380220925-14207-1-git-send-email-bhalevy@primarydata.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <52447EA0.7070004@primarydata.com> References: <52447EA0.7070004@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Anderle We should catch errors in the format at the time the list is given to the kernel, rather than just returning garbage to the client and letting the client fail. Signed-off-by: J. Bruce Fields [removed unused 'len' parameter] [fixup rpc_pton parameters for 3.4] [fixup rpc_pton include file] Signed-off-by: Benny Halevy --- fs/nfsd/nfs4pnfsdlm.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4pnfsdlm.c b/fs/nfsd/nfs4pnfsdlm.c index 906c370..ddc2188 100644 --- a/fs/nfsd/nfs4pnfsdlm.c +++ b/fs/nfsd/nfs4pnfsdlm.c @@ -23,6 +23,7 @@ #include #include +#include #define NFSDDBG_FACILITY NFSDDBG_FILELAYOUT @@ -56,6 +57,25 @@ struct dlm_device_entry { return NULL; } +bool nfsd4_validate_pnfs_dlm_device(char *ds_list, int *num_ds) +{ + char *start = ds_list; + + *num_ds = 0; + + while (*start) { + struct sockaddr_storage tempAddr; + int ipLen = strcspn(start, ","); + + if (!rpc_pton(&init_net, start, ipLen, + (struct sockaddr *)&tempAddr, sizeof(tempAddr))) + return false; + (*num_ds)++; + start += ipLen + 1; + } + return true; +} + /* * pnfs_dlm_device string format: * block-device-path:, @@ -109,12 +129,10 @@ struct dlm_device_entry { goto out_free; memcpy(new->ds_list, bufp, len); - /* count the number of comma-delimited DS IPs */ - new->num_ds = 1; - while ((bufp = strchr(bufp, ',')) != NULL) { - new->num_ds++; - bufp++; - } + + /* validate the ips */ + if (!nfsd4_validate_pnfs_dlm_device(new->ds_list, &(new->num_ds))) + goto out_free; dprintk("%s disk_name %s num_ds %d ds_list %s\n", __func__, new->disk_name, new->num_ds, new->ds_list);