From patchwork Fri Mar 30 17:14:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juro Bystricky X-Patchwork-Id: 10318141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CDD46055B for ; Fri, 30 Mar 2018 17:14:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F37A2A5FA for ; Fri, 30 Mar 2018 17:14:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 636972A612; Fri, 30 Mar 2018 17:14:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFA272A612 for ; Fri, 30 Mar 2018 17:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752425AbeC3ROU (ORCPT ); Fri, 30 Mar 2018 13:14:20 -0400 Received: from mga17.intel.com ([192.55.52.151]:46411 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752392AbeC3ROT (ORCPT ); Fri, 30 Mar 2018 13:14:19 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Mar 2018 10:14:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,382,1517904000"; d="scan'208";a="43581258" Received: from juro-precision-t5610.jf.intel.com ([10.7.198.59]) by orsmga001.jf.intel.com with ESMTP; 30 Mar 2018 10:14:15 -0700 From: Juro Bystricky To: linux-kbuild@vger.kernel.org Cc: yamada.masahiro@socionext.com, michal.lkml@markovi.net, richard.purdie@linuxfoundation.org, jurobystricky@hotmail.com, Juro Bystricky Subject: [PATCH] modpost: srcversion sometimes incorrect Date: Fri, 30 Mar 2018 10:14:05 -0700 Message-Id: <1522430045-31685-1-git-send-email-juro.bystricky@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "srcversion" field inserted into module modinfo section contains a sum of the source files which made it. However, this field can be incorrect. Building the same module can end up having inconsistent srcversion field eventhough the sources remain the same. This can be reproduced by building modules in a deeply nested directory, but other factors contribute as well. The reason for incorrect srcversion is that some source files can be simply silently skipped from the checksum calculation due to limited buffer space for line parsing. This patch addresses two issues: 1. Allocates a larger line buffer (32k vs 4k). 2. Issues a warning if a line length exceeds the line buffer. Signed-off-by: Juro Bystricky --- scripts/mod/modpost.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 9917f92..955f26e 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -385,9 +385,10 @@ void *grab_file(const char *filename, unsigned long *size) * spaces in the beginning of the line is trimmed away. * Return a pointer to a static buffer. **/ +#define MODPOST_MAX_LINE 32768 char *get_next_line(unsigned long *pos, void *file, unsigned long size) { - static char line[4096]; + static char line[MODPOST_MAX_LINE]; int skip = 1; size_t len = 0; signed char *p = (signed char *)file + *pos; @@ -402,8 +403,11 @@ char *get_next_line(unsigned long *pos, void *file, unsigned long size) if (*p != '\n' && (*pos < size)) { len++; *s++ = *p++; - if (len > 4095) + if (len > (sizeof(line)-1)) { + warn(" %s: line exceeds buffer size %zu bytes\n" + , __func__, sizeof(line)); break; /* Too long, stop */ + } } else { /* End of string */ *s = '\0';