From patchwork Sun Feb 19 18:58:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9581761 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 8ED94604A0 for ; Sun, 19 Feb 2017 18:59:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80141285A7 for ; Sun, 19 Feb 2017 18:59:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7506A286EF; Sun, 19 Feb 2017 18:59:21 +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_SIGNED, 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 E8FE8286ED for ; Sun, 19 Feb 2017 18:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751726AbdBSS7N (ORCPT ); Sun, 19 Feb 2017 13:59:13 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:36563 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751690AbdBSS7L (ORCPT ); Sun, 19 Feb 2017 13:59:11 -0500 Received: by mail-io0-f195.google.com with SMTP id q20so3076019ioi.3 for ; Sun, 19 Feb 2017 10:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZHBfw7lNXgpkyJy+aSycXnMqKVp7lb5SA0H9Bajo1Ps=; b=A9/3InJ7F20KgW52jUAWYJiwpJBg/8h20x9L8m4wWtIrX0o6Ce6wLvCwYr/y7E/4S1 iy7lmTPDB0zNy4tTwb3d6s4ePuQoGCutrX7UFLQKMqE7V/k5w13lMpYIlya/y2HkiFJa foJ9ZkivIC7fTz60T68HscDwyhEKQCmfO5/7i6ysuZ1QVXXkAsf2CZ7jzMtV54qhahTU bIA11cLKG3g35f60YQHH5XIslY5T/XIPRil3hIZzGw+qeS98FeJ4es2OrckzoVAPJV7u pra6MUhBfrF3B8l+eehZ7npDDNdkMFrS38iG8tuQGqkRgg/HezVbcJgSwdCkE36OvQii xFYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ZHBfw7lNXgpkyJy+aSycXnMqKVp7lb5SA0H9Bajo1Ps=; b=EwMg5OxKeE9I5O0H6HV9axbesqvAqXbfjqQHmeHaXf/vBxPZWTj7WMcUpNMy0r9w77 0n7LvyVyX8D7Dlm+P6rfYy3kaztmBJtQmMywvL3YdeqImtG69+QRob06aqnBk63YQItG 7BJHZFRxC0fXhhlQwTzCni+qpVh7aWQYvwPbOlVTzL6lEiQv9kIywJjOKRbpoN1jNZdC GPni0RUMp+UH0kHmmTlFq7a7uGSMXql9yN/GHmpXCrcUdOzlzrCiDdWzK3m2IX0JAsTg DhrfczahI3DgBjXxAbc57iCcc0rWkE+y/4COtOBgcnFWGnEvPlMAOdGWBhLo2Wryg4l0 VJQg== X-Gm-Message-State: AMke39nwdCXq+vxUwSHNpQYI02Ta69abXsh9+PAiCZHhZESZZCam0KoFUX844Hwcguk2Dw== X-Received: by 10.107.11.216 with SMTP id 85mr13102180iol.0.1487530750414; Sun, 19 Feb 2017 10:59:10 -0800 (PST) Received: from localhost.localdomain ([50.124.63.84]) by smtp.gmail.com with ESMTPSA id o20sm4039282ioo.37.2017.02.19.10.59.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Feb 2017 10:59:09 -0800 (PST) From: Trond Myklebust To: Anna Schumaker , Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: [PATCH v4 3/8] NFSv4: Replace the open coded decode_opaque_inline() with the new generic Date: Sun, 19 Feb 2017 13:58:58 -0500 Message-Id: <20170219185903.42043-4-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170219185903.42043-3-trond.myklebust@primarydata.com> References: <20170219185903.42043-1-trond.myklebust@primarydata.com> <20170219185903.42043-2-trond.myklebust@primarydata.com> <20170219185903.42043-3-trond.myklebust@primarydata.com> 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 Also ensure that we always check that the size of the decoded object matches the expectation that it must be smaller than NFS4_OPAQUE_LIMIT. This should be true for all the current users of decode_opaque_inline(), including decode_ace(), decode_pathname(), decode_attr_fs_locations() and decode_exchange_id(). Note that this allows us to get rid of a number of existing checks in decode_exchange_id(), Signed-off-by: Trond Myklebust --- fs/nfs/nfs4xdr.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 5f0a6fcd0030..4c40098c184b 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -3050,20 +3050,15 @@ static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string) { - __be32 *p; - - p = xdr_inline_decode(xdr, 4); - if (unlikely(!p)) - goto out_overflow; - *len = be32_to_cpup(p); - p = xdr_inline_decode(xdr, *len); - if (unlikely(!p)) - goto out_overflow; - *string = (char *)p; + ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string, + NFS4_OPAQUE_LIMIT); + if (unlikely(ret < 0)) { + if (ret == -ENOBUFS) + print_overflow_msg(__func__, xdr); + return -EIO; + } + *len = ret; return 0; -out_overflow: - print_overflow_msg(__func__, xdr); - return -EIO; } static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) @@ -5645,8 +5640,6 @@ static int decode_exchange_id(struct xdr_stream *xdr, status = decode_opaque_inline(xdr, &dummy, &dummy_str); if (unlikely(status)) return status; - if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) - return -EIO; memcpy(res->server_owner->major_id, dummy_str, dummy); res->server_owner->major_id_sz = dummy; @@ -5654,8 +5647,6 @@ static int decode_exchange_id(struct xdr_stream *xdr, status = decode_opaque_inline(xdr, &dummy, &dummy_str); if (unlikely(status)) return status; - if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) - return -EIO; memcpy(res->server_scope->server_scope, dummy_str, dummy); res->server_scope->server_scope_sz = dummy; @@ -5670,16 +5661,12 @@ static int decode_exchange_id(struct xdr_stream *xdr, status = decode_opaque_inline(xdr, &dummy, &dummy_str); if (unlikely(status)) return status; - if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) - return -EIO; memcpy(res->impl_id->domain, dummy_str, dummy); /* nii_name */ status = decode_opaque_inline(xdr, &dummy, &dummy_str); if (unlikely(status)) return status; - if (unlikely(dummy > NFS4_OPAQUE_LIMIT)) - return -EIO; memcpy(res->impl_id->name, dummy_str, dummy); /* nii_date */