Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5135663rwb; Tue, 17 Jan 2023 09:34:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXs3MVLPBh02KknT2VgRpIPa2na0bJjnjzmTPkhv8Dyd7ncxAymSCYQ2QMXqdTIcvZkC/KhC X-Received: by 2002:a17:90a:4587:b0:229:bc1:7cd1 with SMTP id v7-20020a17090a458700b002290bc17cd1mr4232786pjg.33.1673976899595; Tue, 17 Jan 2023 09:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673976899; cv=none; d=google.com; s=arc-20160816; b=Fi51Qbi+TchP/DPEEVFCfbIc+N01RcNqsEUKvR86Bz6VYZ8jsoCTdy6bJ1/TlzUgnw BC+0xeAxwn43s0C6cmOjw7ri03V+PF/mPQPbvMkpuIvt9+PmrPvm3N/42wj1nAhH4hCE fPj9/Hdjn1eGUbDyQAhmJl/Q/R6SYk09Nzp4TIf3He66SaTGOsRiIyI9gVTG9bjGXK2Y mNlOciVVoWhIkfECK/k6czoLMrPSOPTSk5sxIc5jN0wiCxoEu70X3O43sWgX+Sbpz4+o Ve3DD2OeFwK0WeqADxCQIYdtDvvRYcUbP3xhfHXSezGh3phW6dr7aP5gunV7Vffs3rqJ wjfA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=185VNqtOqrWbrz+iqnibvY2OKcoNRPZvWlFEs/lSiyw=; b=JRsxvmgELxiEqJsHkaBXGvm+/7zBMR5NjV+8jEGot8zUliBVSUYeB7J+3GoRvem8wi XkGeMzqqMpMDXEXuKgF0d1lwO78ey9DTMcQSTn03QsKQbjfy0U7H37EVFQ/Jwsv5J3xR wWCoaEkmpIi8WblCArwU6ySSyUpoX3LhcJP9GcbQYQ+P8JkqJHn+a93ifFJ65QYkm+wI kMNkAk/1S+BCXD4LfdTwDvDe8iMy9OEcIMC2lF9G6ZHqoHOuYTsuRpaZYTQY3pgYT9QB WocWgcOncWGyPWPEQaCUXJ3tRWHgz/4ydYDTtkr+Q/FGTlK5XyFu15h/UDWwIuLY9C4H oFhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=DFisV2MP; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pi17-20020a17090b1e5100b00229125f1426si17285711pjb.19.2023.01.17.09.34.54; Tue, 17 Jan 2023 09:34:59 -0800 (PST) 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=@suse.com header.s=susede1 header.b=DFisV2MP; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232356AbjAQQMO (ORCPT + 48 others); Tue, 17 Jan 2023 11:12:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231584AbjAQQML (ORCPT ); Tue, 17 Jan 2023 11:12:11 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18A283B3D3; Tue, 17 Jan 2023 08:12:10 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9E4E01F385; Tue, 17 Jan 2023 16:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673971929; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=185VNqtOqrWbrz+iqnibvY2OKcoNRPZvWlFEs/lSiyw=; b=DFisV2MPDS3tQ97+t5ehDa1oiSns+MsIadujPEsel0Q3rDNaZ88r2bgBdYYDX/JAu3gGpr phicHXPF6isX3ScM6jjUBVLwHeex3nLoYufaOlT/aVGoU7XFuWz4hSLRG5F8adkUylQhyi VcXUynz/RJ7SEwQw3AdBsjbPa8ESaJ8= Received: from alley.suse.cz (unknown [10.100.208.146]) by relay2.suse.de (Postfix) with ESMTP id 4A24C2C141; Tue, 17 Jan 2023 16:12:08 +0000 (UTC) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , coverity-bot , "Gustavo A . R . Silva" , linux-next@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek , coverity-bot Subject: [PATCH] printk: Use scnprintf() to print the message about the dropped messages on a console Date: Tue, 17 Jan 2023 17:10:31 +0100 Message-Id: <20230117161031.15499-1-pmladek@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 Use scnprintf() for printing the message about dropped messages on a console. It returns the really written length of the message. It prevents potential buffer overflow when the returned length is later used to copy the buffer content. Note that the previous code was safe because the scratch buffer was big enough and the message always fit in. But scnprintf() makes it more safe, definitely. Reported-by: coverity-bot Addresses-Coverity-ID: 1530570 ("Memory - corruptions") Fixes: c4fcc617e148 ("printk: introduce console_prepend_dropped() for dropped messages") Link: https://lore.kernel.org/r/202301131544.D9E804CCD@keescook Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 55338bfd3b55..a9b7dade0d2e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2716,7 +2716,7 @@ static void console_prepend_dropped(struct printk_message *pmsg, unsigned long d char *outbuf = &pbufs->outbuf[0]; size_t len; - len = snprintf(scratchbuf, scratchbuf_sz, + len = scnprintf(scratchbuf, scratchbuf_sz, "** %lu printk messages dropped **\n", dropped); /* -- 2.35.3