Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp657418pxb; Tue, 5 Apr 2022 17:35:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx91Xtx//D1K+yQuhIgztO8kT6qij15UJwdKl/CeotMps11ZS8eFsY+Fey7hkoIWTtaODV3 X-Received: by 2002:a50:d098:0:b0:41c:bd64:b0de with SMTP id v24-20020a50d098000000b0041cbd64b0demr6099159edd.366.1649205330435; Tue, 05 Apr 2022 17:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205330; cv=none; d=google.com; s=arc-20160816; b=AQ23EIJT43wvDwLRzK/Qqzu+beqZBNcpaYDYhDLClfAXpvVs9S0Hu7GZZAviYIi/3b 8VTGcjkxay5kn+TdDgSMGc2RYx7qOw8hqC9UXq+Ex5jJHTWdby25b62cl98WYpazWE3j sd3RFqAZmlIG5wV/h33r9q3Ri0l2WijdqSlH45JLJLSgwjuJXCF7jTvJZ1dnT3UoFf8w eS9uickHhCsDeq2bwDq8OlQC47DipJMHqti7svCJBlzM9+opNuRg5n7h+aQuvOBCchAP Uber4x60eKg91YdxDGhePeoODHLSY8uuTi24UiZ/nGiEI099VNoHThP1tClwxRGxaBk2 3mNA== 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=Ehf54wg9VBYlz39jHQziyMQG6pP3unyiPVmJcPmqBFE=; b=hcuQiNMRN7+iPQ4DfH34qRCJGBDNXFGm/za+0F+mz8Ugd8IkMruBAOpDHP1Ss3FAd+ UsftiMGCMi7NTEjCe6QJ24uoacABrIHfth/kZE0p2+aUKcsick2oqGQkzOEcdqiZu5RZ UBx5+SwvHwcJMHQQ7xT6zcyDvYdFU/5t27SnZC10wtWnheW0LntFmmNz3LyQgh6rWIi4 YwvSGjtG2un+AJjyh4KQjLE7Ry7BLomE8d4mvNQUQ52R7sOAUJNbfRuqmEUkgnkqdOiy cARuSfPvHfCVzcsUbqAnCFmOR2Gw8rP6Napk0Of7Q7Om8QgeZdanuFPqlNvP38ZJA9OJ PcIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a6qsemaC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a50a6ce000000b00418c2b5bf41si9561599edc.547.2022.04.05.17.35.05; Tue, 05 Apr 2022 17:35:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a6qsemaC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1348197AbiDELCf (ORCPT + 99 others); Tue, 5 Apr 2022 07:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236351AbiDEIlX (ORCPT ); Tue, 5 Apr 2022 04:41:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0549D1103; Tue, 5 Apr 2022 01:34:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BD103B81B13; Tue, 5 Apr 2022 08:34:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31C8CC385A0; Tue, 5 Apr 2022 08:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147649; bh=8mb2t1vcLixCqqs5leqyvJaYwmzvz3X3Dz9GErrHCoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a6qsemaCJ8w8JN5t+1p1kvzTzXxkwKZ7OZr8nD5IQWLTzQmSq6omfl4q8wQz8pXsd P/xYGrYMH5IVlTJryEfeNV+QxsWQbGRu8H7omvRdkL833eTCgHw5KEv1Ts7fl7l3hX n2YRkuTLnxDhyGfty++fwsX8174hO8u9AaopvmyQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anssi Hannula , Mathias Nyman Subject: [PATCH 5.16 0034/1017] xhci: fix garbage USBSTS being logged in some cases Date: Tue, 5 Apr 2022 09:15:47 +0200 Message-Id: <20220405070355.192087192@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anssi Hannula commit 3105bc977d7cbf2edc35e24cc7e009686f6e4a56 upstream. xhci_decode_usbsts() is expected to return a zero-terminated string by its only caller, xhci_stop_endpoint_command_watchdog(), which directly logs the return value: xhci_warn(xhci, "USBSTS:%s\n", xhci_decode_usbsts(str, usbsts)); However, if no recognized bits are set in usbsts, the function will return without having called any sprintf() and therefore return an untouched non-zero-terminated caller-provided buffer, causing garbage to be output to log. Fix that by always including the raw value in the output. Note that before commit 4843b4b5ec64 ("xhci: fix even more unsafe memory usage in xhci tracing") the result effect in the failure case was different as a static buffer was used here, but the code still worked incorrectly. Fixes: 9c1aa36efdae ("xhci: Show host status when watchdog triggers and host is assumed dead.") Cc: stable@vger.kernel.org Signed-off-by: Anssi Hannula Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220303110903.1662404-3-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -2624,8 +2624,11 @@ static inline const char *xhci_decode_us { int ret = 0; + ret = sprintf(str, " 0x%08x", usbsts); + if (usbsts == ~(u32)0) - return " 0xffffffff"; + return str; + if (usbsts & STS_HALT) ret += sprintf(str + ret, " HCHalted"); if (usbsts & STS_FATAL)