Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp315436ioo; Fri, 20 May 2022 23:33:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrivEGDEcGGOI36CClfWCtYNFkOnJFnkOpyAToLdxviyhQJmhF0DZvC9AXS+UekKACAy8O X-Received: by 2002:a17:90b:180a:b0:1e0:176d:f6e9 with SMTP id lw10-20020a17090b180a00b001e0176df6e9mr1875650pjb.156.1653114823297; Fri, 20 May 2022 23:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653114823; cv=none; d=google.com; s=arc-20160816; b=c5N1tiMhE8aV/nL05yPShHJNvEygFww2ql/qiHDXe7B3oKR4Li0Q+7t5Wb4etH6pTN KTLinuQMyK/LimPGaOz/87lZZSfL5Qu7rPY3nm0Lt2fwVj+yDLQztq0sNJ5X/45sF0p3 QqsXuBlbqGkvFQkljjNkigM3s5kzfC0abQdzzN4lZf6cPkwh8PkxWk1q3MaXuD8qs1Nk NmEulbQ4HjgVE4ep1gJBkOF69AUEAZ/bl4UI6aNcpExaKTRrcS4JmL5xkIIKXOfQddGV PCuqVpV1Yh/NEgGlG5gYE5priFPFbwfEkY98KvSSDPPfd/nImR3qaRWmifEAdSgqu5de pD/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=2237/Ofuxqe67/VYFRa9P3BISgr2hp9724ybcz8E9F4=; b=LXQvGrtTkbo+C4nqRoIgRq6HlP4bNrb8QKP57l/QWXPAvuI5bbzww68h75/mCrxSSh YO7ZkwpYKigg4Hav+EcrdFjsXmCgJh+S4koNMRY2JLSyybWkkKGYoxYDRZM/Iz3Za8vN qzQzfVvQme5F/0DOhvoiqao9HxDg0KJIHxV14jO4+gQ5nqx4NBrAXCqe04JxFfwL+FsY zjbc9oIB73VdESFqdLh/m5zeFsh5FNZXqMSIcgp/KdExnDF3loRV5LtcNwbPKGlZYyv9 FV4HyvlRh97wgtXw1q64Vd3uBTiZpVALaa6+wENxK/RBMwwCGsgVzkyUPiY/KcuqKV78 DT3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=u8EuLCU4; 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=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob10-20020a17090b390a00b001dfa16d2c26si6457303pjb.138.2022.05.20.23.33.32; Fri, 20 May 2022 23:33:43 -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=@samsung.com header.s=mail20170921 header.b=u8EuLCU4; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347423AbiETIkJ (ORCPT + 99 others); Fri, 20 May 2022 04:40:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347278AbiETIjM (ORCPT ); Fri, 20 May 2022 04:39:12 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8B059E9F7; Fri, 20 May 2022 01:39:05 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220520083904epoutp01d633c5bcdcb6da73271b21c597906494~ww27ZggBF2627726277epoutp01N; Fri, 20 May 2022 08:39:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220520083904epoutp01d633c5bcdcb6da73271b21c597906494~ww27ZggBF2627726277epoutp01N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653035944; bh=2237/Ofuxqe67/VYFRa9P3BISgr2hp9724ybcz8E9F4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8EuLCU4damLDZX89+GSfa5zldk34IKUPwDaK6R19ZlesjN7mpBhJsbdnTTWC3qDM fObGoLvRtp1uMLJfVvZnPfccUAhB8mogz6NlgreqwZCLKObcXlegTji+lQFr2s3Flw pokB64aAUXpFmH+syf18ARawGRcf2nl2fHB5465I= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20220520083903epcas5p3adf18f19c5ed99372f394308244c18ae~ww26m8o2E0240402404epcas5p3-; Fri, 20 May 2022 08:39:03 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 3F.B5.09827.7A357826; Fri, 20 May 2022 17:39:03 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20220520083733epcas5p4ff2414309bf128f40b0bbd3adde52297~ww1nQxUww1594815948epcas5p4M; Fri, 20 May 2022 08:37:33 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220520083733epsmtrp1ebe1d16f82b71ff5466e4767a66bb9a8~ww1nPCU0l0237202372epsmtrp1R; Fri, 20 May 2022 08:37:33 +0000 (GMT) X-AuditID: b6c32a4a-b3bff70000002663-8c-628753a72e5d Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 12.FB.11276.D4357826; Fri, 20 May 2022 17:37:33 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220520083725epsmtip23ee302e3ef5a51c52121b1c30ddb4167~ww1f26llB3055130551epsmtip2R; Fri, 20 May 2022 08:37:25 +0000 (GMT) From: Maninder Singh To: keescook@chromium.org, pmladek@suse.com, bcain@quicinc.com, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, satishkh@cisco.com, sebaddel@cisco.com, kartilak@cisco.com, jejb@linux.ibm.com, martin.petersen@oracle.com, mcgrof@kernel.org, jason.wessel@windriver.com, daniel.thompson@linaro.org, dianders@chromium.org, naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com, davem@davemloft.net, mhiramat@kernel.org, peterz@infradead.org, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, rostedt@goodmis.org, senozhatsky@chromium.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, akpm@linux-foundation.org, arnd@arndb.de Cc: linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-modules@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, v.narang@samsung.com, onkarnath.1@samsung.com, Maninder Singh Subject: [PATCH 2/5] kallsyms: replace sprintf with scnprintf Date: Fri, 20 May 2022 14:06:58 +0530 Message-Id: <20220520083701.2610975-3-maninder1.s@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520083701.2610975-1-maninder1.s@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-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5Y/+w5X8LQGW2GCfZVrfVq6eknERnJPPBZ6rSGYM9ybWWUf NoobnBwm1toiOafeQq35GziX4ffVPb7sn28y4TmINT4TGZ+JChBWjjYJSWqlXKkOTwpPFD6X qGVK9alEueSzk8p6tPpfoVtaUHP5lKQDYQzqQByDiwNESKlN8BMdlZ1JFVQn41SnFIK6AwUx hHijqDfDFefHymXJwglBSBJU/6cY4xOowfSZU7+4i2YlTWe7Mr8r2Ox/u8ZQ2VWqq00feJ4c ZaVDe56MXLsef0VrqV3ouRL0xYN9ER9UdZ6J+thXLq1akmZtqThscocthOShHOdrd3rtebrN ou+bFW9tPWu78GnsNOGwzm1sMDhu4gV4fNDh6B0vx6QOvH4geiziK0t1+6Hcr9v6FCneTc9F t71rjY29lBKhN20IqjLL+9dP/rQ9bVwe4B3ZuquJyd5b/+KJnZJiZ8njlOrbBnzykM/SR2X7 T0ddbYMGRn/ElpravGu2OGSiP3o2wcjHHUw+tzvspXGv7nHVm0ytfNtFxzbzlPTD34LL0J5/ Y2Ka72dYr8fttL5v/3KdmFAfk4WH4iq17D/cxLrazgMAAA== X-CMS-MailID: 20220520083733epcas5p4ff2414309bf128f40b0bbd3adde52297 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20220520083733epcas5p4ff2414309bf128f40b0bbd3adde52297 References: <20220520083701.2610975-1-maninder1.s@samsung.com> X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 replace sprintf API with scnprintf which prevents buffer overflow. Co-developed-by: Onkarnath Signed-off-by: Onkarnath Signed-off-by: Maninder Singh --- kernel/kallsyms.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index f354378e241f..9e4316fe0ba1 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -472,28 +472,29 @@ static int __sprint_symbol(char *buffer, size_t buf_size, unsigned long address, name = kallsyms_lookup_buildid(address, &size, &offset, &modname, &buildid, buffer); if (!name) - return sprintf(buffer, "0x%lx", address - symbol_offset); + return scnprintf(buffer, buf_size, "0x%lx", address - symbol_offset); if (name != buffer) - strcpy(buffer, name); + strncpy(buffer, name, buf_size); + len = strlen(buffer); offset -= symbol_offset; if (add_offset) - len += sprintf(buffer + len, "+%#lx/%#lx", offset, size); + len += scnprintf(buffer + len, buf_size - len, "+%#lx/%#lx", offset, size); if (modname) { - len += sprintf(buffer + len, " [%s", modname); + len += scnprintf(buffer + len, buf_size - len, " [%s", modname); #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) if (add_buildid && buildid) { /* build ID should match length of sprintf */ #if IS_ENABLED(CONFIG_MODULES) static_assert(sizeof(typeof_member(struct module, build_id)) == 20); #endif - len += sprintf(buffer + len, " %20phN", buildid); + len += scnprintf(buffer + len, buf_size - len, " %20phN", buildid); } #endif - len += sprintf(buffer + len, "]"); + len += scnprintf(buffer + len, buf_size - len, "]"); } return len; -- 2.17.1