Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp648398pxv; Thu, 15 Jul 2021 12:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw79JwLte5hxHQosXgik6duDTcR4jna6bcb+eXVp7dp3srEzLdu10xnATuDEME+8zLGdx+ X-Received: by 2002:a17:906:c29a:: with SMTP id r26mr7355973ejz.235.1626377124683; Thu, 15 Jul 2021 12:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377124; cv=none; d=google.com; s=arc-20160816; b=M1OVgo3xPWulELONTq+e2PB1CxriuKcQZDwd6av2Oj2tm2ph4cHegxyUSf397ZViCQ lUjXzykZgPPVlHF7x4xH0/HPDDpqxUEd2XDIsoU5BGhP9zTrPdcaRpLYYUSDj65WHbpn 7TawDwTtbtQH3Ep4tpMklQZIeruQ4uyyhe6liPriLfe0KDj3aFU3CpRoPQC0zZNX4MnU x0eq6n0nC5W/KBvJ5cZ6ZeOfPd4gr259F3JkVFSte3pqiwRMOYM8gQM0lL76bxjBKKEE ckOsmk4J25cGJWzOoGEAOk71DvGqnHpn06C8Nm27ibe5x4x6nhCJGMD3ZfWNfCvKVggC FRqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KdONhzBYUllNNt3c+k1ZdW2MbZyrqACsL51vVxVEtRo=; b=bt+mWLRnLWnZwCjmToxfm5s4tkSd8nXmOkzfETeIOX0Ymo8yR/Qg0rBl8q/BU5Rkch obMqLOtiPKHVnBKkHNK0ngbZZpSPxM6lUYcgOCJOK/gV6MGBkzmXUdRe/rSvS7+FmDGm 3EqDRVKpge8+vJj1UNP8KN9o/cHx0+eu2OFb86YJ+fm7l+69Bqx7djCVIOhQf4mY0Mlo vxHA+UXpnqAnwY+CkFm09+6jvRwZ82iUGz9acFzodcDnXMhOyIJm1NFE3I0omtPlTOMb bIuYl0jNhk8kHoVYKPl+TJPa/xrHzQPDJfA8edKjRnPhHfO8LCQRSzFZRG0ByTkB4AyU MRbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VOq9UWkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qb36si1129012ejc.403.2021.07.15.12.25.01; Thu, 15 Jul 2021 12:25:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VOq9UWkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245675AbhGOTYW (ORCPT + 99 others); Thu, 15 Jul 2021 15:24:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:45860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241077AbhGOTHa (ORCPT ); Thu, 15 Jul 2021 15:07:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46117613F9; Thu, 15 Jul 2021 19:03:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375808; bh=SC0SrYxpAj381JD7DFm4xcmROiC9Ok/KwUycPC30xhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VOq9UWkOGkjR6sEyZ5JGbIV8QfaF+n7zdHFgCXYEp9mCS5BUMQ+dBLnQT6L4ITd7A KeErOCiGWUioSMDLLvAbAH2L1/dCunARm8jwy6l8q3r9NMWnw213PM1fxOdZqfk/RC Dxo1SNeg5wk3TF20kHQo6bz7KmjV7Zdk/oyEfhQc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yun Zhou , "Steven Rostedt (VMware)" Subject: [PATCH 5.12 208/242] seq_buf: Fix overflow in seq_buf_putmem_hex() Date: Thu, 15 Jul 2021 20:39:30 +0200 Message-Id: <20210715182629.880367460@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yun Zhou commit d3b16034a24a112bb83aeb669ac5b9b01f744bb7 upstream. There's two variables being increased in that loop (i and j), and i follows the raw data, and j follows what is being written into the buffer. We should compare 'i' to MAX_MEMHEX_BYTES or compare 'j' to HEX_CHARS. Otherwise, if 'j' goes bigger than HEX_CHARS, it will overflow the destination buffer. Link: https://lore.kernel.org/lkml/20210625122453.5e2fe304@oasis.local.home/ Link: https://lkml.kernel.org/r/20210626032156.47889-1-yun.zhou@windriver.com Cc: stable@vger.kernel.org Fixes: 5e3ca0ec76fce ("ftrace: introduce the "hex" output method") Signed-off-by: Yun Zhou Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- lib/seq_buf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/lib/seq_buf.c +++ b/lib/seq_buf.c @@ -229,8 +229,10 @@ int seq_buf_putmem_hex(struct seq_buf *s WARN_ON(s->size == 0); + BUILD_BUG_ON(MAX_MEMHEX_BYTES * 2 >= HEX_CHARS); + while (len) { - start_len = min(len, HEX_CHARS - 1); + start_len = min(len, MAX_MEMHEX_BYTES); #ifdef __BIG_ENDIAN for (i = 0, j = 0; i < start_len; i++) { #else