Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2404920lqp; Sun, 24 Mar 2024 18:08:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBC46/hf1fj0VqyBA3L1RVXynyFdSxkcZkq5tyJeRa4nTribhQYiUXuvGZ/y7XXTI4F8yDqO/TnOeLEcS2dEKKIR9N/lfYj7TrQIM+tw== X-Google-Smtp-Source: AGHT+IGHgyTJSd5pbJf0MB6j8+G/vEkZYDqu78VrRS5sx2MUBvOJiAc0EVdVJMJ7OaHomQG31TZ1 X-Received: by 2002:a05:6358:590d:b0:178:6211:871 with SMTP id g13-20020a056358590d00b0017862110871mr7000717rwf.0.1711328915722; Sun, 24 Mar 2024 18:08:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711328915; cv=pass; d=google.com; s=arc-20160816; b=BhYd53vXp1i9Fq3mqJSTkddDiGp3qQf3fw0KvYftmVeVq1LrW7Cxiwnkgr6Bqgz+PS jqonqElfx6LGS4fqnJqsvo9+1RFmsu8PSjJckSTJqzNt1RLV3yO2Rr5K8xKX4U56diZk yIT1tzZN85oCu8UFdU85Xq75LVjQQAqpoI7V1dHhmhDKDEJk0TBYsNpSyJTvUpCcgqaA JNioe2kf46XDvtUWbhGlWpj+V2ZHZWwhixRPgEkquQrDsB0BrmxJkmP6uS8eehRT5ACy CPNlXmIEuDSw/DHZCQuc/yMJumND8t+Ikk41hG/prs+1EvwuPxi7Mk2vl/LlDkoY0/j1 0ZIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zeqAzF4VM0rpLgTNGw+IZgvFx3INxo/WALWKXDQ0Ojg=; fh=6+9f8U16DeY2SD9AQ5owd8paFMl9NCtcHFp7+/0usyI=; b=vhOErNsgJfTU0aTT4iuPsD8ymMQRWeKGk3rXY1DmQXF8PmEVD7iwGvtwf2fffrNIBx 6B6BAzVVIvYf02Z+lklpSTUWiJTwz3KmQg5wP42s0PD1K9dXOIHbLU4+h8BYcRsHPugM sOcvFxtA7Llc5wN6yU+JNLFDMLcebNl0jo5dOh0MgVMVpPovLzWm1hMTrqjlUAmWXb/V lqZPTP+jqjAoHEhKH4PzDgcDf3n+6FhXUAwli4cm8SdWuhBU8wx/CPquvs73N6rZDno7 dvBofUDu6dlYQlLljhSBOkJVNNQCv/NnJimIJxg2LwBEbALpgsoxrT60f1JrpOJpR8e/ 8kvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YLgKwcuT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p2-20020a63fe02000000b005cdf992367dsi6578604pgh.730.2024.03.24.18.08.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:08:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YLgKwcuT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113463-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AB939B24522 for ; Mon, 25 Mar 2024 00:43:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A1BF1B1FEC; Sun, 24 Mar 2024 22:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YLgKwcuT" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 887771B1FCE; Sun, 24 Mar 2024 22:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320264; cv=none; b=gIRJChwOOFechH5CeBxtkjBUAlJMsQyCG+taVy6UoooLQbIn2beo5GVefJTPdgweSSwGLtcleBSvTp40h37GxyxZTvMjsRiLCJkESPz6qzOk6qDJTpo6asxWv+9hJOZ0vnNJz0mk+a/oglnydXwRJKK1PQWfKWeRjBW8kDlyCyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320264; c=relaxed/simple; bh=DnIEbnQD9ob1MO8/v30ZkD/ZbTdidfNE4UviQRjCoEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JIQWBE1iM1bv1qtkHFSnL2Q8cWiHU8o8dtZRZzi8asVeHgWCxQBB2t/4cvAud7/x73TnQJPEwTCUTPt9MFUCwnrLxHELdG+mY1/r38WQBTNYq2HUfBT3pkE9Xq7vKcCC0tdaUSSrkQxqT70ZoJD2zmYdIj2aFo0WolyCRA8c9yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YLgKwcuT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0BD9C43399; Sun, 24 Mar 2024 22:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320264; bh=DnIEbnQD9ob1MO8/v30ZkD/ZbTdidfNE4UviQRjCoEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YLgKwcuTyyrMaJrtxanZhjBBSwdxx4vHWL+DIF+GTAkT0Kwt1bLbEZ3Wo99IjBM+c kkK3pGDFzxxoUOCjITuu0V5SvFxHNMXycMSQmR9MbOnRlBLnnOcZyXPSnjpX1rH5RO YqTUpD4UpDa9xgN8VUgohdpd+JOXoLEoRkiwHTL0CZ074XCzb5jKb0ih3TQgh2kRho IvGb5/+FVGbsxnEAheiAApgGZG6A0Sn4YsukBbbiGMKnaZTaM2YQa2ngfzxjLexG9l RVsK3rI9GbIKvi+EglVNT/QXQOdq0DH/psBHGm7uNt6VWZZd3HDQw0ZAEyv4pbbI9X 8TSPrL0KY7C2g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexey Kodanev , Jack Wang , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.8 572/715] RDMA/rtrs-clt: Check strnlen return len in sysfs mpath_policy_store() Date: Sun, 24 Mar 2024 18:32:31 -0400 Message-ID: <20240324223455.1342824-573-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Alexey Kodanev [ Upstream commit 7a7b7f575a25aa68ee934ee8107294487efcb3fe ] strnlen() may return 0 (e.g. for "\0\n" string), it's better to check the result of strnlen() before using 'len - 1' expression for the 'buf' array index. Detected using the static analysis tool - Svace. Fixes: dc3b66a0ce70 ("RDMA/rtrs-clt: Add a minimum latency multipath policy") Signed-off-by: Alexey Kodanev Link: https://lore.kernel.org/r/20240221113204.147478-1-aleksei.kodanev@bell-sw.com Acked-by: Jack Wang Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c index d3c436ead6946..4aa80c9388f05 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c @@ -133,7 +133,7 @@ static ssize_t mpath_policy_store(struct device *dev, /* distinguish "mi" and "min-latency" with length */ len = strnlen(buf, NAME_MAX); - if (buf[len - 1] == '\n') + if (len && buf[len - 1] == '\n') len--; if (!strncasecmp(buf, "round-robin", 11) || -- 2.43.0