Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879Ab3HTDOL (ORCPT ); Mon, 19 Aug 2013 23:14:11 -0400 Received: from intranet.asianux.com ([58.214.24.6]:5944 "EHLO intranet.asianux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751713Ab3HTDOJ (ORCPT ); Mon, 19 Aug 2013 23:14:09 -0400 X-Spam-Score: -101.1 Message-ID: <5212DEC3.9070007@asianux.com> Date: Tue, 20 Aug 2013 11:13:07 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Rusty Russell CC: "linux-kernel@vger.kernel.org" Subject: [PATCH] kernel/module.c: use scnprintf() instead of sprintf() Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1503 Lines: 35 For some strings, they are permitted to be larger than PAGE_SIZE, so need use scnprintf() instead of sprintf(), or it will cause issue. One case is: if a module version is crazy defined (length more than PAGE_SIZE), 'modinfo' command is still OK (print full contents), but for "cat /sys/modules/'modname'/version", will cause issue in kernel. Signed-off-by: Chen Gang --- kernel/module.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 2069158..0618e63 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -603,7 +603,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s) \ static ssize_t show_modinfo_##field(struct module_attribute *mattr, \ struct module_kobject *mk, char *buffer) \ { \ - return sprintf(buffer, "%s\n", mk->mod->field); \ + return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \ } \ static int modinfo_##field##_exists(struct module *mod) \ { \ -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/