Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3854050pxv; Mon, 19 Jul 2021 10:18:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3/IR4ZuN+GgpE2rvU4AihMe24L6Z5JmarsuPNYJzHoRV8RlFxurZ6N7con5hzMmgGT2ym X-Received: by 2002:a5d:8752:: with SMTP id k18mr19703257iol.139.1626715106567; Mon, 19 Jul 2021 10:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715106; cv=none; d=google.com; s=arc-20160816; b=QB/rvB4DZ/2FwovO7e/NtIIOVBdiDEou98q/GirNuS9eaptLYHMTn0jVvIp14vgaX0 Mjza5KqlOIdCXVHbkEKtjlB7GLlHubfywW2MTcmXZXoRdBhTCp8dCZec3zZnNVxrJHnb 208lhMDYoc8468vo3r8QdwcF+ia9aie/+hNAAQ03nntra4FY9hIHOpBvpPAr7f5DVdHz wF9Nr5yp9fpMxd1AxIrRP1MtLB5XkOS5JWZWBh7tKpmRixNZmQ2PjfCPnhGt3ugVlry5 9C4zqxv0rvPdn11il2yzFAltRdXcHJ6q+eRhwAsa3wyLPKW3c/E6MSkwlLVxJx3eFhr/ 72JQ== 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=aWiPFnBer3ARUOOjp9ztm+PpUnrMArd+DhnuQaX+iXs=; b=SWsi0hFz3OZQ/l4dI4mY1ZY9/CMsexCzMBdFTUSk/kdmX/6vGhLE7ikOJ3yDGnK6pg 7di4UBCBmq7JlLXZ3olhsa1j8sXmebp6y46MlrAqXtkIv5/rU43aq2xR3jT/2ya10rBS UfN6JYjmP9joDPlKdjTB3Mb1mmf+JZxLxGbA8IJv4VV6jnyRnc/iHaInN/Ueksv0qpl4 R1voJiADRAKTFfghGQ+vTjyizJlWmZojzfN3x5C8I1U5ztzwa4FdH4Uqpd/CbXtb+Wu9 H/OEvvOE2E9VYEl5aFRDuvSIZjKOv1tOytTd7Lbt60gXkhFtGRdzqA4UEof4Vq9xfqJG RJZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VWhDTobL; 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 z24si20857435jap.49.2021.07.19.10.18.14; Mon, 19 Jul 2021 10:18:26 -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=VWhDTobL; 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 S1355004AbhGSQfl (ORCPT + 99 others); Mon, 19 Jul 2021 12:35:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:40022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347964AbhGSPXc (ORCPT ); Mon, 19 Jul 2021 11:23:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F2C6961264; Mon, 19 Jul 2021 15:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710398; bh=ALUg3I4EgJTJjOYjclxtb3GuqXylJMBR65DGoO+kQf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VWhDTobLoYu/ppGc0VKLVdu+/PuTuwHKrAaMRq/wuROTz5UAgayRgl4/FD9pVZx8r COFmT2HdcYTz2SNR9cDjUYs80Xe5tLPMRL6Sih38P70O7jEItcrWtRznH9omuNp9a4 LJSxWEXeQxzydfRConU1n+fH1FHntr7WTJWTn/1g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Alexandre Belloni , Sasha Levin Subject: [PATCH 5.10 199/243] rtc: fix snprintf() checking in is_rtc_hctosys() Date: Mon, 19 Jul 2021 16:53:48 +0200 Message-Id: <20210719144947.352753665@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@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: Dan Carpenter [ Upstream commit 54b909436ede47e0ee07f1765da27ec2efa41e84 ] The scnprintf() function silently truncates the printf() and returns the number bytes that it was able to copy (not counting the NUL terminator). Thus, the highest value it can return here is "NAME_SIZE - 1" and the overflow check is dead code. Fix this by using the snprintf() function which returns the number of bytes that would have been copied if there was enough space and changing the condition from "> NAME_SIZE" to ">= NAME_SIZE". Fixes: 92589c986b33 ("rtc-proc: permit the /proc/driver/rtc device to use other devices") Signed-off-by: Dan Carpenter Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/YJov/pcGmhLi2pEl@mwanda Signed-off-by: Sasha Levin --- drivers/rtc/proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/proc.c b/drivers/rtc/proc.c index 73344598fc1b..cbcdbb19d848 100644 --- a/drivers/rtc/proc.c +++ b/drivers/rtc/proc.c @@ -23,8 +23,8 @@ static bool is_rtc_hctosys(struct rtc_device *rtc) int size; char name[NAME_SIZE]; - size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id); - if (size > NAME_SIZE) + size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id); + if (size >= NAME_SIZE) return false; return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE); -- 2.30.2