From patchwork Sat Jun 23 20:49:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ploumistos X-Patchwork-Id: 10483843 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 5EC6560230 for ; Sat, 23 Jun 2018 20:49:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 468E8289DD for ; Sat, 23 Jun 2018 20:49:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A11428A19; Sat, 23 Jun 2018 20:49:50 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 B6303289DD for ; Sat, 23 Jun 2018 20:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751393AbeFWUtt (ORCPT ); Sat, 23 Jun 2018 16:49:49 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:42482 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbeFWUts (ORCPT ); Sat, 23 Jun 2018 16:49:48 -0400 Received: by mail-wr0-f196.google.com with SMTP id w10-v6so9820475wrk.9 for ; Sat, 23 Jun 2018 13:49:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=nVw17CH67n/k23hh75At4jtkQMqNig6/XykHQcXx+5I=; b=YitKpwrp5Gn4S7f9/fUeeykeYmiczIrgLxhzgnVrBuFsTGFE9HWqGpAunTplXkcauj cuZc32OlE6EyCh1+CSWF98JEhxPZBP1BFS7NovlM88PSlaGe8Hd+5GEOveWzg1iWfKfh 8/wwdyEK2ECHj5y/UTBJSzjMIg/Y/bgoNSL+K69qUeOfRvmrpQEpodd7es5L6nKSAVAW 3Y+OzkV889G2x+BAtBay0TelKdh9xWdOhJzkbUQMjRSBgDoTSfk8I8LBpE3yMJKdXycu CZ8XfSq87m8YuZGqb5S8lMWnEymzED+mUt5Qnb1kadtbRLNHEGNEwjJQVpmfR96yqS3x DgNw== X-Gm-Message-State: APt69E077oh5a+qbRntbVNe3cGULXcHTq3gvJtKETi2jG1TDZNlOhrsC 8knJojSEAAaYyVNpEk8p3gk= X-Google-Smtp-Source: AAOMgpfu4wfc3Pc77W84XGxyvaRrPenCV5p1IJbd0HmEay++t1Sj2HUYbcwDlm6U5y4avepXlRlbqw== X-Received: by 2002:adf:c844:: with SMTP id e4-v6mr5436056wrh.236.1529786987407; Sat, 23 Jun 2018 13:49:47 -0700 (PDT) Received: from localhost.localdomain (89-157-150-237.rev.numericable.fr. [89.157.150.237]) by smtp.gmail.com with ESMTPSA id p3-v6sm12262223wrn.31.2018.06.23.13.49.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Jun 2018 13:49:46 -0700 (PDT) From: Alexander Ploumistos To: yamada.masahiro@socionext.com Cc: linux-kbuild@vger.kernel.org, labbott@redhat.com, Jerry James , Alexander Ploumistos Subject: [PATCH] kconfig: loop boundary condition fix Date: Sat, 23 Jun 2018 22:49:04 +0200 Message-Id: <20180623204904.11378-1-alexpl@fedoraproject.org> X-Mailer: git-send-email 2.17.1 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 From: Jerry James If buf[-1] just happens to hold the byte 0x0A, then nread can wrap around to (size_t)-1, leading to invalid memory accesses. This has caused segmentation faults when trying to build the latest kernel snapshots for i686 in Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=1592374 Signed-off-by: Jerry James [alexpl@fedoraproject.org: reformatted patch for submission] Signed-off-by: Alexander Ploumistos --- scripts/kconfig/preprocess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 65da87fce907..5ca2df790d3c 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -156,7 +156,7 @@ static char *do_shell(int argc, char *argv[]) nread--; /* remove trailing new lines */ - while (buf[nread - 1] == '\n') + while (nread > 0 && buf[nread - 1] == '\n') nread--; buf[nread] = 0;