Received: by 10.223.185.116 with SMTP id b49csp1066570wrg; Fri, 23 Feb 2018 11:18:09 -0800 (PST) X-Google-Smtp-Source: AH8x225za1UnOQVWFNLq7rjT9VKfYX4n9dLT0+VXi22aYjS4ZEyXI+zXLJgHxfxQ9cUYx8AdabUa X-Received: by 2002:a17:902:968d:: with SMTP id n13-v6mr2701917plp.33.1519413489650; Fri, 23 Feb 2018 11:18:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519413489; cv=none; d=google.com; s=arc-20160816; b=ZJTSBjyUYU53BXanGcEEz4NODCYTsMwxABfSlecbxPAyJZjc7ENZVuWHECm/MQ0rnI sQ4nVKeAXhnEnxvCsdKikgQfKLhCxb7w3LTA0Qk/Qj8cC3Ieux1SPIPk7k3KpnDDZvHV cysB2re4XiDA4fQStvzm19mFFQgU3BJuFn+/Fc3HOG6hXv6L6VwTxqnx83WCXrwMXjum ZF2L7pSC0nXRAIZYcFvD0XSutaHO/cUx7Fb5/6iY8KZKnAo3ViSWMd9zxcBRkZtg1Kw+ zzmFY+bEbqamAf6d26XRQLH2BKMYHeraZufHQlF2hhcI7DWwR8ZHMVOxbDA5wZOO9oOm BI/w== 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=1g9PAakW2s68J7YQpqdTvjd5FpJlLSFCV9zPPeyvyFU=; b=BdObaB4l09ZVsHvn8fz3eYnShrjlJvhEfQ/rxqUW7vRPHfJSjfS3SyJ0iQStf9vr// tXeXJdK8E4q9IwVc9heQC+Xmc1x1KvSZiKzo0OLfvp47HwruSYnAaSfrfldDypJs2F+N Ep/avsD0SqIFzWSpaV77WppNtuf+rge1Y60n/d89Ptw4fxbqiMgpbdt5ObThU+WhBorZ gLA/2778VgJmHPZ7TNDTNe55/PDTq1jgyMfdTpIa3iZe61cOtFBGBae/7oaUeTsnGtdp Cq/fGyZ/m/qRypOrcg87e2BuA/3ARmtD+LZHm1czRhirXxc/1VEww3ssnFbFTkpAACtY IZVw== 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 3-v6si2149850plr.440.2018.02.23.11.17.55; Fri, 23 Feb 2018 11:18:09 -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 S1754441AbeBWTQ5 (ORCPT + 99 others); Fri, 23 Feb 2018 14:16:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48006 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965048AbeBWSy7 (ORCPT ); Fri, 23 Feb 2018 13:54:59 -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 254A111E9; Fri, 23 Feb 2018 18:54:58 +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.14 126/159] 509: fix printing uninitialized stack memory when OID is empty Date: Fri, 23 Feb 2018 19:27:14 +0100 Message-Id: <20180223170758.414548522@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@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.14-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);