From patchwork Thu Nov 18 19:44:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 47902 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75011385AC34 for ; Thu, 18 Nov 2021 19:45:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75011385AC34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637264759; bh=omgPSTQBXtancHuni8qwTBKKrF0jYk+ixoaeAoaWTCE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=DTDZ2helWU2trYngYB/kXki/K6ntwQFQJeX7AJHosYGfvsP8H4SrMnA6wr2eAiGq2 R6F/7VbolKDtyovx8DRT5w9ghwzKid/dSKgN3MHCIMOFIIuOjelmvKtEZTbTCtULs0 /AfGx6OVqvdctZY0CVnGFZDdQXWJ+i5PnxBUpag4= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by sourceware.org (Postfix) with ESMTPS id B2B443858422 for ; Thu, 18 Nov 2021 19:45:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B2B443858422 Received: by mail-ed1-x54a.google.com with SMTP id b15-20020aa7c6cf000000b003e7cf0f73daso6202617eds.22 for ; Thu, 18 Nov 2021 11:45:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=omgPSTQBXtancHuni8qwTBKKrF0jYk+ixoaeAoaWTCE=; b=a3T10hcOngOOVt0mCSH8XUlrZahqBNjcz4xL3aBMd2H9Rb9w15TeZSIPswapAmuFP1 qlSkWIH3Cm+xmltupPAKRu+EFYnPw73mK2XWTdCccUlP08FgO1TSYvSIeIEdnlTbQ9E3 EWjT9UPjTED8jjnBkPDxll90vj8si2ujGf6TyEUwLal1ZiDwD4asJ7Jp9CYgdECEcnwh iHWnbT8XUhSPYdhWvZ7qlzThafubeWbeKixdGB2sg3lTQJfjfp55rwSJZ9VIb0p1NSCD f5fFWohkSAzg2okp1sMfqTOk2GAsYu4a028OYtFnlA5QALYdoqQES4oiPse+fc/+Xksu r67A== X-Gm-Message-State: AOAM531tvN8UE2rEeJtLogOSw7YcOpmHLqHCUzwitfHPiZssnd/Ur9Il m/dw8I7MGSlgDpzGLQAvnmXYgic4ZgnXNrC2DliQxlKcilCSFj4Pj9hvtXmM3bPje+fY9fi9o7i fPniPX3kfGls7oTtLVaGlbYf/96OB9q8udR4WulD34c2MGiHrTG6I7Xs7qnlsHf42h7RzXm0aRr ff X-Google-Smtp-Source: ABdhPJwoyouFrwpnrttmJEjzEZEI3w20+cXF6Mq+Phd7IdrpZj7l2MuF+GnHTq+g9U/mqxtsgOSSDMmKjxYDdw== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:9c56:1357:f0b9:90b8]) (user=maennich job=sendgmr) by 2002:a05:6402:4412:: with SMTP id y18mr14667081eda.103.1637264749528; Thu, 18 Nov 2021 11:45:49 -0800 (PST) Date: Thu, 18 Nov 2021 19:44:50 +0000 Message-Id: <20211118194449.1931428-1-maennich@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH] dwfl: fix potential overflow when reporting on kernel modules To: elfutils-devel@sourceware.org X-Spam-Status: No, score=-22.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matthias Maennich via Elfutils-devel From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: kernel-team@android.com, Paul Pluzhnikov Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" dwfl_linux_kernel_report_modules_ has an outstanding ancient bug when reading kernel module information from a modules list file. The target buffer for the module name was sized too small to hold potential values. Fix that by increasing the value to account for the null termination. In practice, this unlikely ever happened, but it now got diagnosed by LLVM as part of a stricter -Wfortify-source implementation [1]: libdwfl/linux-kernel-modules.c:1019:7: error: 'sscanf' may overflow; destination buffer in argument 3 has size 128, but the corresponding specifier may require size 129 [-Werror,-Wfortify-source] modname, &modsz, &modaddr) == 3) [1] https://github.com/llvm/llvm-project/commit/2db66f8d48beeea835cb9a6940e25bc04ab5d941 Suggested-by: Paul Pluzhnikov Signed-off-by: Matthias Maennich Change-Id: I97b4fcb536273e5ccc4e37b0b9f0f8ffb7487909 --- libdwfl/linux-kernel-modules.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index c0f8dfa4aef2..58c0c417a597 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -1008,7 +1008,7 @@ dwfl_linux_kernel_report_modules (Dwfl *dwfl) int result = 0; Dwarf_Addr modaddr; unsigned long int modsz; - char modname[128]; + char modname[128+1]; char *line = NULL; size_t linesz = 0; /* We can't just use fscanf here because it's not easy to distinguish \n