From patchwork Sun Feb 5 14:02:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 9556085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B9BBB60236 for ; Sun, 5 Feb 2017 14:03:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3ADB205F8 for ; Sun, 5 Feb 2017 14:03:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9870526785; Sun, 5 Feb 2017 14:03:49 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 410EF205F8 for ; Sun, 5 Feb 2017 14:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751101AbdBEODr (ORCPT ); Sun, 5 Feb 2017 09:03:47 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:34271 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbdBEODq (ORCPT ); Sun, 5 Feb 2017 09:03:46 -0500 Received: by mail-it0-f68.google.com with SMTP id o185so5982770itb.1 for ; Sun, 05 Feb 2017 06:03:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=5ggjJehjDVmPa6NzQN4ViEQ/WmkopzZlr4zWOeXRQzs=; b=SCL6Wd54SbAAoMiFLAdPkVvJ4HHpnsSWNPirbkymn5DsUjeHFUz8FYjrLllZySlyN9 EoA+WaolypK/Ll4ru+dQ3WqP5ZRjl08Yz3ghrhxoAM43JrxZXhZhnvjhrcWbC80rPQ8k BAhU5CbL/pXIf/mIoXTORQyXYuI9DaMRIglE2mnEHLtcuXs5pQq1xtsTxnMI9+30D+Mo Wq1exzdY+m06bu/lzAjAEQB0ojxRToA//IEFpQxKDzoq31jsxzykMRJ1nV2oXYLa5BZ6 ATf0TVehqU95HIyr1CBJjXt7uC02MzBs2Bo9TWNS+AjFu6bTMy0n7V6TNQIn1W/v06W2 y+Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=5ggjJehjDVmPa6NzQN4ViEQ/WmkopzZlr4zWOeXRQzs=; b=Pz5f1MiUKs+Fe4sOvztRzlyGWNQ22EuvYec1V9KnWTQi3LG2tEC6goURt4otx24cNj bcuKY6iq6W8wd/OzFsTtIyzKcrieY5XwOt7eEe2a8Km7GDp+S9UjhFZ6JcgLJclAq1iC pLp7QY3B73hsIawzbc88uCJJSd8vbsaW6iZ94i+hmeoNJYFK7Px/4SifKVgq8KJJPB1C iO0ZLVzPaDmTFHlQ2CtmH2Nbg4Fm+LefAEhUgofAZRfy0fctspRoe2EgXxspVlATd02k KTp2qcCZqCHV854RMFQWBOkIP31F3yN15Q0+NrlkBQALFohSYrYLiRYGRqWseCk9eowb 6wYQ== X-Gm-Message-State: AIkVDXJMutwlw8H7ZXf8wLkKdGeOkEqpHqbmsrkcVyEhS7NBYY5jg5tyQilETa6P2XaSsw== X-Received: by 10.36.214.86 with SMTP id o83mr4253463itg.97.1486303425476; Sun, 05 Feb 2017 06:03:45 -0800 (PST) Received: from [192.168.0.107] ([182.139.117.200]) by smtp.gmail.com with ESMTPSA id a129sm6097349ioe.15.2017.02.05.06.03.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Feb 2017 06:03:44 -0800 (PST) From: Kinglong Mee Subject: [PATCH] nfsd/idmap: return nfserr_inval for zero length principals To: "J. Bruce Fields" , linux-nfs@vger.kernel.org Cc: linux-nfs@vger.kernel.org Message-ID: <25d503f0-c330-1401-2ed6-693c97fa8970@gmail.com> Date: Sun, 5 Feb 2017 22:02:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Tigran Mkrtchyan's pynfs testcase for zero length principals fail as, SATT16 st_setattr.testEmptyPrincipal : FAILURE Setting empty owner should return NFS4ERR_INVAL, instead got NFS4ERR_BADOWNER SATT17 st_setattr.testEmptyGroupPrincipal : FAILURE Setting empty owner_group should return NFS4ERR_INVAL, instead got NFS4ERR_BADOWNER This patch checks the principal and return nfserr_inval directly. It should be check after decoding in nfs4xdr.c, but it's simple before process in nfsd_map_xxxx, so adds it in nfs4idmap.c. Signed-off-by: Kinglong Mee --- fs/nfsd/nfs4idmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c index 5b20577..6b9b6cc 100644 --- a/fs/nfsd/nfs4idmap.c +++ b/fs/nfsd/nfs4idmap.c @@ -628,6 +628,10 @@ nfsd_map_name_to_uid(struct svc_rqst *rqstp, const char *name, size_t namelen, { __be32 status; u32 id = -1; + + if (name == NULL || namelen == 0) + return nfserr_inval; + status = do_name_to_id(rqstp, IDMAP_TYPE_USER, name, namelen, &id); *uid = make_kuid(&init_user_ns, id); if (!uid_valid(*uid)) @@ -641,6 +645,10 @@ nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name, size_t namelen, { __be32 status; u32 id = -1; + + if (name == NULL || namelen == 0) + return nfserr_inval; + status = do_name_to_id(rqstp, IDMAP_TYPE_GROUP, name, namelen, &id); *gid = make_kgid(&init_user_ns, id); if (!gid_valid(*gid))