From patchwork Thu Feb 8 10:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 198274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp67370dyd; Thu, 8 Feb 2024 02:19:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqxMUxaiIixLm84z7Y3ZZZqM+NKA48VyHeESzuacP7/xjy81EVsGCIay5bVijEU9Hmikya X-Received: by 2002:a05:620a:298c:b0:785:9c72:5ec3 with SMTP id r12-20020a05620a298c00b007859c725ec3mr5356713qkp.75.1707387552755; Thu, 08 Feb 2024 02:19:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707387552; cv=pass; d=google.com; s=arc-20160816; b=qF9SztsqQCpvxZt0NERFTEh9YnnERAd9IcTu7ZydF0xIk0GVewaV0U85wqxv0HwaCk K9DgkLBc5zItKEeJAbXwlW8tbiA+4REK76gLfO6aGj/drp8ETbiRaeRRp5ta6Cu8IZ37 kRiCkglAehJ4MGtr7+p5ur6A4qlR4tG7yueJ63aGLHz+AiGHyKkirNg46rVFCbbIZgjW BaCnfqzesOwcCYS0MVpUjVZQgwXGsH0FYKjDZPwDjysUZwTdtM0VAFuVcuSuC/hkeMhC Qk6PlVcA5qPXrM3mdHc5NqPdbWHnjhAmCVJ47VdIkO0z76nA6DnQnYb0wrS+6KgUdFSh 2/uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=U3l3rhYnvc20HMeICU1VJe+MdTxuoHKteQqL6qQ8unM=; fh=hpQMMFPp8Qmpil5gI9K6L/QY7/NMloG6wsOH+DrTlZI=; b=Uqo82opOk10AEXzeB2oAsIRNWjQcezI1+q/etOmn4jIm9ZBC4UFIDdbcF9xPTcQh8Y q7ko4qxymtWOi2Uee/Dms1UmikKBV5UFpxv7UVOMlKn2aHs1hRwOr+xyt6dN1AwE8rBZ 9i3cWPhBrTtRSv4ZIayO7RrdGCk0u7O1tOWCj1avSEch1uXcM0ta00kXTmOF2U4KDD6+ SHTLDsLj+pydkjcTuMlIxbBKUPvbrRYmXexL+zCEPjNLCvEMPOCWPrfG8Y7kfSSWIRgd fPdcwNhw04a1wHaOll/yLq6ZLe85jcxCzx1X9foqVegmlwWYqwFNUZG7rD5BQQDUb2Ux wBFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jB4/BiFb"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-57834-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57834-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=2; AJvYcCWPTASms6dqTIS06PjuhrKHFbOzBOxF9YEXQTC7HdIIUOz+Ocq5apMRMCTxML06eym06xz6y4Mu+zTqpxjuAd2Zkey7hg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v9-20020a05620a090900b007859d5b3788si2808118qkv.522.2024.02.08.02.19.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 02:19:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57834-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jB4/BiFb"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-57834-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57834-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7B42B1C22A49 for ; Thu, 8 Feb 2024 10:19:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B6CC6E2B8; Thu, 8 Feb 2024 10:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jB4/BiFb" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AF546D1A8 for ; Thu, 8 Feb 2024 10:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707387533; cv=none; b=iAxMhfwJKlVHYXSBStbOXo1VlM2ew64sEpzWNTrIS5f20MmDSs5eA38qtuGDQJdBVtFT+alkGhdcvaFi/GFG19bRZLpEYwwGnx1gVEPr9FuDsxN6fAxFGpwrrzdUGbKUdz09OHlPi92pRvUtUF53gvYO7i10hgYKxyQLPOzMYjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707387533; c=relaxed/simple; bh=+wnJqL+pqGvJcwEHa93fmS0oXb5TjuFDPjn/Uorknjs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=dj4DmyCONmG3lwn45WTygN8rJ8PZUmjojSsDPJHWEVRm9RHya73Ty8BMylW9v5GTAvus1Spn8uzZVludao7qAXCWIBqN9BOZzWx46IpyqUdUc5pkaVCpnunstO0uxHNcdARj8cI2cC1uDWQgRQCoimHexpysmtQk3/ZOzEquVM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=jB4/BiFb; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a38291dbe65so192051466b.3 for ; Thu, 08 Feb 2024 02:18:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707387529; x=1707992329; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=U3l3rhYnvc20HMeICU1VJe+MdTxuoHKteQqL6qQ8unM=; b=jB4/BiFbDvXzCzynzmAuD5C6DIwNLQBrP3G1CpsI/F0VpIyiaADzlF4slsJIrvsSMw pzDlYynZDMe4/CK38whOh03tOL4I/ZeWJ0EGsdUB+8pcbUa2lEtKQet7G6XBa+dJ/Tp+ 9tOBpKjd4r/iua1FxG1B6i3Tx46sKtsEBdlZI/9hBZ6weLmiTql+yKSGJVFvleWZpWqa FTc4gPKqM6qBb+7BVPd/kxyE99xlARsXEdXTvTjxX0hzk7Klicd/d+kxUMeot9xl65FS UpVVQd7WVqtSwnztK/05g8CPDk+fJlcxVxZt2xAlCuiXXEpTO73O5jFVmiVNWc6bEY9m 8v7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707387530; x=1707992330; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U3l3rhYnvc20HMeICU1VJe+MdTxuoHKteQqL6qQ8unM=; b=WBxVGMLa880+zgPB48EKlzdMM3bJBh+6GPL7UgNa9AQ9tMoj/J7LalZNS8st1yIMnY Go9ZGST9BUEsr0na5rKEDpcZg5eyjo0+GQqol83OBouLs+c4++2aAbUA/Uatci7MO401 oNdMDVr/XEJHmzJSmrFkkQ4daf+2uZ8z8oc9fNucaZIlsC3nWmFrs9/7vOHYDZ4fGB3B HCBMUFjgD4wBMhTZTHFCI81Fbix47CcQjBrupDNgoGxxOZDt13fuY+CpEJI90kx1a9tM 9BRwk1XjzOSZ0GY14mMw50urZwYw2BfXIgbrfw+5Q8p7d+bY7XZ9lvXgmvJc3T7h25Kc o7Uw== X-Gm-Message-State: AOJu0YzaUP3zfbF7TFhm3pA8MOcV1SvDQLWprttyGmYbCED/6wK/GlbS Lcrc3zvzsRo4OeASrdzIAHDwZay8ZEG70B47lLV1AfsW4rxBwkAAqHvwbhtzWLg= X-Received: by 2002:a17:906:386:b0:a37:3b00:199b with SMTP id b6-20020a170906038600b00a373b00199bmr6727416eja.30.1707387529681; Thu, 08 Feb 2024 02:18:49 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVnj0O9VjVBXDc9EkEsJ3HBmiZix7NO1jblKXDiOm1U0BHjdFpDjp3SJVaHoWpFWNli0Kt74isuuHqJVBtULNlTVxyshw92DSgDV6EoUgv2kQnnqDnMpxlugArvm2jsxuYn9h3Faz4AQUffrBdCto960O/HhVY/hhA+F5ZbmGjtCkRttyKq3t4ELUsrmOW0sSSa4f8chX043hiYVZP5gO+Ts/tiRUYRph6Wjy2ZkW6umKwYRnFi0my/gVhwF3+gIEG/qjwVak5YyJKA6cm9cEBngYeTah+VhqQ7gCQKe28OqzdNmgZKJWtaAQRr56XrXyfx9KcDTU7TZPPy7VfeNbRuU4sv0trFfsC71586wZrsAxh7YDLujH4= Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id hw19-20020a170907a0d300b00a376d1a18adsm1753615ejc.98.2024.02.08.02.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 02:18:49 -0800 (PST) Date: Thu, 8 Feb 2024 13:18:46 +0300 From: Dan Carpenter To: Aurelien Aptel Cc: Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] cifs: fix underflow in parse_server_interfaces() Message-ID: <05c63e91-ce29-40aa-807c-ac730181c83e@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790325610051671353 X-GMAIL-MSGID: 1790325610051671353 In this loop, we step through the buffer and after each item we check if the size_left is greater than the minimum size we need. However, the problem is that "bytes_left" is type ssize_t while sizeof() is type size_t. That means that because of type promotion, the comparison is done as an unsigned and if we have negative bytes left the loop continues instead of ending. Fixes: fe856be475f7 ("CIFS: parse and store info on iface queries") Signed-off-by: Dan Carpenter --- fs/smb/client/smb2ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index b79b6bbd7103..bb3975dc9072 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -620,7 +620,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf, goto out; } - while (bytes_left >= sizeof(*p)) { + while (bytes_left >= (ssize_t)sizeof(*p)) { memset(&tmp_iface, 0, sizeof(tmp_iface)); tmp_iface.speed = le64_to_cpu(p->LinkSpeed); tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;