Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3208270pxb; Mon, 9 Nov 2020 05:38:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzNZEdwGoKJoEWFFrTBFiZojIGeZH73uvM/lLX49y9ZXBZlfXLxykjXXVRjPRZa8h66ZdK X-Received: by 2002:a17:906:3a1a:: with SMTP id z26mr14634580eje.519.1604929079849; Mon, 09 Nov 2020 05:37:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929079; cv=none; d=google.com; s=arc-20160816; b=tjrUZRBQK7aGXppztQi0oQdm9d22Dtii8PMWLcOBPGiIsHBUJJF81G9DRs9dswZDh7 oOeWFQOSNYIzWjaqL4rP5f+EzhE+eMHtoeICbgVKAb7+WNoawPTdP8MP17AKe4EWpOJk WQh3gWMHN434XSE7YWjp4hZnnAVrpUHGtpgReSAhkrNLNaA8Rls2c8Y4uocCtlK/8VBU 9qXZEaPV8vHbeVTz/s08LjPsVPvvP6Nt6D16WKkQq4wjb73Trb+YzRHq5UqWMR2GHrH3 Lq/oDlhTEum0em9o/ptv3LWQ9plR1nJp0uYFCedaN+/75qkDg3zmeTEGHhSf2X57XSVx XJAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=AbxTIA4ww5DiFFWnwIsRe8oQeA0Jc5q1pHim7wKikXk=; b=iIADltP1W1hQuBGFPzoCSvqYMdr3RWzMQ2mstiv4kclvGcn0rKSnyb/QRh8ljFUH4G S9wbHGJvRyXl1MdUIC8ak0wQwmBnR7K7pdc9i9YJiCgFnZXjhVRCQF1RzE6aL3h/uRA2 VThxm5jsHtuPfxHg5f+VZGYzaV603dXXF6JHlrci4b+IACLh3coVT3qJEtcTraGmrhr0 S/bTNouMFJb7rMWHw6tGV+d+POSXJORwgjK748C7NIqfRpqb4m+mzewdAl1AsiSROoZe KEDBBY3FAJpXXFs7ub8qEqosMklSrlTMyAdXYFWb29CnaGAE4oiSkB4jpFJsdvIsuagC g0IA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si7462769ejt.126.2020.11.09.05.37.37; Mon, 09 Nov 2020 05:37:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731491AbgKINgU (ORCPT + 99 others); Mon, 9 Nov 2020 08:36:20 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:51656 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730753AbgKINEv (ORCPT ); Mon, 9 Nov 2020 08:04:51 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kc6ql-0006it-A6; Mon, 09 Nov 2020 13:04:47 +0000 From: Colin King To: Paul Gortmaker , "Paul E . McKenney" Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] cpumask: allocate enough space for string and trailing '\0' char Date: Mon, 9 Nov 2020 13:04:47 +0000 Message-Id: <20201109130447.2080491-1-colin.king@canonical.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently the allocation of cpulist is based on the length of buf but does not include the addition end of string '\0' terminator. Static analysis is reporting this as a potential out-of-bounds access on cpulist. Fix this by allocating enough space for the additional '\0' terminator. Addresses-Coverity: ("Out-of-bounds access") Fixes: 65987e67f7ff ("cpumask: add "last" alias for cpu list specifications") Signed-off-by: Colin Ian King --- lib/cpumask.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cpumask.c b/lib/cpumask.c index 34ecb3005941..cb8a3ef0e73e 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -185,7 +185,7 @@ int __ref cpulist_parse(const char *buf, struct cpumask *dstp) { int r; char *cpulist, last_cpu[5]; /* NR_CPUS <= 9999 */ - size_t len = strlen(buf); + size_t len = strlen(buf) + 1; bool early = !slab_is_available(); if (!strcmp(buf, "all")) { -- 2.28.0