From patchwork Wed May 28 16:15:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 4256421 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 F0997BF90B for ; Wed, 28 May 2014 16:16:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 10FB220155 for ; Wed, 28 May 2014 16:16:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C55C200F3 for ; Wed, 28 May 2014 16:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754381AbaE1QQK (ORCPT ); Wed, 28 May 2014 12:16:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54121 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754130AbaE1QQK (ORCPT ); Wed, 28 May 2014 12:16:10 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4SGG0uZ008928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 May 2014 12:16:01 -0400 Received: from smallhat.boston.devel.redhat.com (smallhat.boston.devel.redhat.com [10.19.60.65]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4SGG0Ww003010; Wed, 28 May 2014 12:16:00 -0400 From: Steve Dickson To: Libtirpc-devel Mailing List Cc: Linux NFS Mailing list Subject: [PATCH] Avoid buffer overruns by allocating buffer in svcauth_gss_validate() Date: Wed, 28 May 2014 12:15:58 -0400 Message-Id: <1401293758-8506-1-git-send-email-steved@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Signed-off-by: Steve Dickson --- src/svc_auth_gss.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/svc_auth_gss.c b/src/svc_auth_gss.c index 601a691..e31010f 100644 --- a/src/svc_auth_gss.c +++ b/src/svc_auth_gss.c @@ -280,29 +280,35 @@ svcauth_gss_accept_sec_context(struct svc_req *rqst, return (TRUE); } +#ifndef RPCHDRSZ +#define RPCHDRSZ 128 +#endif + static bool_t svcauth_gss_validate(struct svc_rpc_gss_data *gd, struct rpc_msg *msg) { struct opaque_auth *oa; gss_buffer_desc rpcbuf, checksum; OM_uint32 maj_stat, min_stat, qop_state; - u_char rpchdr[128]; + u_char *rpchdr; int32_t *buf; gss_log_debug("in svcauth_gss_validate()"); - memset(rpchdr, 0, sizeof(rpchdr)); - /* XXX - Reconstruct RPC header for signing (from xdr_callmsg). */ oa = &msg->rm_call.cb_cred; if (oa->oa_length > MAX_AUTH_BYTES) return (FALSE); /* 8 XDR units from the IXDR macro calls. */ - if (sizeof(rpchdr) < (8 * BYTES_PER_XDR_UNIT + + if (RPCHDRSZ < (8 * BYTES_PER_XDR_UNIT + RNDUP(oa->oa_length))) return (FALSE); + rpchdr = (u_char *)calloc(RPCHDRSZ+MAX_AUTH_BYTES, 1); + if (rpchdr == NULL) + return (FALSE); + buf = (int32_t *)rpchdr; IXDR_PUT_LONG(buf, msg->rm_xid); IXDR_PUT_ENUM(buf, msg->rm_direction); @@ -325,6 +331,8 @@ svcauth_gss_validate(struct svc_rpc_gss_data *gd, struct rpc_msg *msg) maj_stat = gss_verify_mic(&min_stat, gd->ctx, &rpcbuf, &checksum, &qop_state); + free(rpchdr); + if (maj_stat != GSS_S_COMPLETE) { gss_log_status("gss_verify_mic", maj_stat, min_stat); return (FALSE);