Received: by 10.223.185.116 with SMTP id b49csp1138462wrg; Fri, 23 Feb 2018 12:36:49 -0800 (PST) X-Google-Smtp-Source: AH8x226ct0hRBNwTK9UlT62QP7MKZFu0j5/9MXGJTvZWzes2PzxGF0Vvx+Zti2T8rKeN7S79shZW X-Received: by 2002:a17:902:74c3:: with SMTP id f3-v6mr2831565plt.444.1519418209024; Fri, 23 Feb 2018 12:36:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418208; cv=none; d=google.com; s=arc-20160816; b=REy/7Im6VtedlKcrlVvNQPc+O1gLhO7S5550sJ1n2wQekghnkxORHuBSRPpoeTNk9A 7w5LsaBfMDMdi2TGudErMLGJPlCzM9w0bqyckKCaQIPoXbxRibO+cbXcicrrwpqAkv62 MGMmpG3uDGote0uccI4SXbo1qeDglDMQnfIBigHke0i2AmwBqdvy9vZe8C2tayOkEG+X 31WtLotqsd5weg9gyNQj8AbJC6JE5KVsZCBAqXqDgYwbkfLFMSe+Q0tOtFV8li0A0U06 t12vU+Tan7XNKaBclLGbFxtfhN6QppNUhobJNrGZ8Ze32pGUXOZD+2YaaH5y9ZxkPpEV 7E9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=zcI60uaD45xBQrnVxK8w7OIYn5a0+hl5RS4eVBRSTsI=; b=w1owKiePq0BPYM7uH08p2+qVNIREWdxb8QrKw7Yw98EBgHmtNDJg5FyhM7gUOsMebk Ts/IEcgVdQAOm0fcJnqFjQy3ssyN9CW6me8h6JvtqFdC9CGD5v+s/JQ80vXlk9Y6umSL CNpW73psbDCT2b3qx6qiK6mu7jgSXk2lDkJWw9rmLmkcnSkmsSifRLz3Ah80wQr5GEz6 n2jggEOUlyc5X8du5XTj0rh3GK/9b62mwILMoSh2Fw6ad1yUtpBI4clG/YohD5uceITe V5QNUHyZGMqT7xFMEi1ycb3LaBPOsc6kMgS3xeQxD9b5UXwhkoDtz1uDxdx7igrWzgdp Fsdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b59-v6si2281139plc.596.2018.02.23.12.36.34; Fri, 23 Feb 2018 12:36:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753654AbeBWSev (ORCPT + 99 others); Fri, 23 Feb 2018 13:34:51 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37068 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753619AbeBWSes (ORCPT ); Fri, 23 Feb 2018 13:34:48 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 748EE1241; Fri, 23 Feb 2018 18:34:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , David Howells , Sasha Levin Subject: [PATCH 4.4 049/193] 509: fix printing uninitialized stack memory when OID is empty Date: Fri, 23 Feb 2018 19:24:42 +0100 Message-Id: <20180223170333.671846766@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers [ Upstream commit 8dfd2f22d3bf3ab7714f7495ad5d897b8845e8c1 ] Callers of sprint_oid() do not check its return value before printing the result. In the case where the OID is zero-length, -EBADMSG was being returned without anything being written to the buffer, resulting in uninitialized stack memory being printed. Fix this by writing "(bad)" to the buffer in the cases where -EBADMSG is returned. Fixes: 4f73175d0375 ("X.509: Add utility functions to render OIDs as strings") Signed-off-by: Eric Biggers Signed-off-by: David Howells Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- lib/oid_registry.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/lib/oid_registry.c +++ b/lib/oid_registry.c @@ -116,7 +116,7 @@ int sprint_oid(const void *data, size_t int count; if (v >= end) - return -EBADMSG; + goto bad; n = *v++; ret = count = snprintf(buffer, bufsize, "%u.%u", n / 40, n % 40); @@ -134,7 +134,7 @@ int sprint_oid(const void *data, size_t num = n & 0x7f; do { if (v >= end) - return -EBADMSG; + goto bad; n = *v++; num <<= 7; num |= n & 0x7f; @@ -148,6 +148,10 @@ int sprint_oid(const void *data, size_t } return ret; + +bad: + snprintf(buffer, bufsize, "(bad)"); + return -EBADMSG; } EXPORT_SYMBOL_GPL(sprint_oid);