Received: by 10.223.185.116 with SMTP id b49csp6376286wrg; Wed, 28 Feb 2018 08:24:05 -0800 (PST) X-Google-Smtp-Source: AH8x226sLcXEVUqKULZtKqe4hfV1JS13TeifByuFG8NahxJSkuUkQ1EZI/ZAx2bW5vhV2JxeII7o X-Received: by 2002:a17:902:8ec6:: with SMTP id x6-v6mr18859297plo.402.1519835045212; Wed, 28 Feb 2018 08:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519835045; cv=none; d=google.com; s=arc-20160816; b=ijkvQbCeEHSoZbLFiYgv6A3GJKwo7Lv8jb5Po34y1DQYPkF1v5PPFGZD1YOCK3w/Sd VCEOQ+z641FftraayF2lBB3+1zmcspuA6mNmO3C+SxBnIulDvQQFyEAayuoqHDNU+zry BHBHvY3KlVzXW7JbBt3W4WtmauE1FgJxJV+e45DhMcdJRO3BRoxXAN9F64bVNfiqyUVY QKeDFiD2sbIBc+e29BE3w1SV/wrVV46dLwCluZTXBwEi+7qjmhIEElX5DYLZ5WCOU88a yY3qYrampPhftlKp9WWA5hQJQVDkhN9qhmzsNWoGyBaL3CABNdIP/g1rX5Aalb7WA/Pd NPUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=b0O666utzqZToqcXdGc5Q86pqu9+oy9HB/r9niBimog=; b=G/URvpVPsKjwggHjEEuRy4kExuYbRVq9XH0aXS/K4kANACyQgvXBeN6CHjRhE/1I4v OFPoMqzDxDdu900HEF9cWFc8tccGAZkS8+bnaDHiVXy7VR8pTf4BBWheNq28aZoxucqQ Ltts7IL6iEbKDEe2JlG8JhCgW97iDoTi2Bnm/Ha+YKz0rfmL3hnbiEKfRhPNutJt6d5f qJiFjSiK/oytVpYOpiidWpVJbVayNUV/1zOlw9eYqUdklvkylkiAYj7sqhHCPm7t2pUf 6ERdfjvtldgSn+EoIwMGG1mEfrvUQX0D5dnHYWGVrqLRSneTndD0B6VmE/IA4oGrpb4b EyDw== 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 z96-v6si1511421plh.35.2018.02.28.08.23.50; Wed, 28 Feb 2018 08:24:05 -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 S935262AbeB1QXL (ORCPT + 99 others); Wed, 28 Feb 2018 11:23:11 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35392 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935067AbeB1QUu (ORCPT ); Wed, 28 Feb 2018 11:20:50 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yg-0006Xb-PV; Wed, 28 Feb 2018 15:22:19 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yf-0008TK-9Q; Wed, 28 Feb 2018 15:22:17 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Eric Biggers" , "Eric Biggers" , "David Howells" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 076/254] 509: fix printing uninitialized stack memory when OID is empty In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 8dfd2f22d3bf3ab7714f7495ad5d897b8845e8c1 upstream. 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: Ben Hutchings --- 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);