From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 C84E93242DF for ; Wed, 8 Jul 2026 17:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783531186; cv=none; b=moiGafm05t83ZHk3ZTChst5FOe5vZtXdWlPqgsrXNWq7EPrSfVSEW7QeD5ikHQ96Ns8xpZxalu/JiKxrKIqdY0bwOzXwOUG4kc46jZi/eEZVBXPvR/Wd/BS2uhAHxH2XrDxLkvl2gk7lPISFdOfbY2f/5zZ0/Jhow/OhaDXlJDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783531186; c=relaxed/simple; bh=nYArZr/ivOQF0A7iQjFdsVD5vyBnmzldNwqEJH3RES4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Spzai4v4dGVjJxApf1XaOoeGastwdTkJKN1Sieog3mEZLJ0Hj93zhCXshBYttjcRWHSyGLTAB+QrtAyTgQDIeO3iiCz8ACb8wyFRPFFfluLQkruKvWt3xWVoHhCgxXGxBZw0E15TPdl28soGqVgyvmI9kJ131g3Osh25xD685WA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hkNIeQG6; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hkNIeQG6" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4758b2a9e2aso667506f8f.2 for ; Wed, 08 Jul 2026 10:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783531183; x=1784135983; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=RnsIaqmcg7oc2NYtCjzbTOj7OJolFMsogq7yyBNf6d8=; b=hkNIeQG6jhOH0/a64lEmkw9HBdremThmzmpzfemtRquj/sR5U2ioHD9fEQSxY7KvFM fdFuL4P2jqRhmNAi7OfaWX0QT8m7fO3YXn8kIaoDhoHzE7//ZsRPBUCgIwpEBdonRFdt B3ReVwIOO1heMtEnziBt/eYZOqujGr/tnmZGNvjWqaBIaXu5ZsY8k7oiEZ5JvgmDZUaJ Ulg1YPGOnHlGALu2c327lP+0J/nJBHxIBzuOtTVakiqqMeL4dGc6up44bxVwMQNBy0ly TtB8dWwM/iQ55argBJ6H5/tSaR/By3Oqz2Gn3w/ukE6LM+tZdq2M7/w1is1pWOMZywrO o9UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783531183; x=1784135983; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RnsIaqmcg7oc2NYtCjzbTOj7OJolFMsogq7yyBNf6d8=; b=dgM/7wgXLc+hE+wIbXCkPIogCz5WoQg1gzdzwuu7MmUqUoBCflNvGtNh7ew9x8JSBN hlCdKMAQEvyXWEaEurVM1WOcL6pvhhaCL+k36rbPQeZLgpnCKlk2cL6K9x9sAexwPwlm T0FvmSII+hWwiLR5UBbGfxIHFKbajNq0XpKSmBuB5dzBm+ivYT2rqRLxnpM4XOAJnwsO kHwWioTUg0sPhexIZK8wQLTL0XK1PmGtRdHzRyxG8AQSGQPuIj1NU1Glop7MnOY53Jhm iMppNohuZYynAs56HAbz+4DhwMJ7DA9QIjx0NhPKSKNzSYXlsKEdPRV+xT36zon5wMyK JAPw== X-Forwarded-Encrypted: i=1; AHgh+RrdoBEA+a+3XWUmd/dLjrTNN1EOi1LQh5zK0TsOIyg44uHgUHZUXpKAE/lg2xmi7IuAIIB+Uj0IduAUg+0=@vger.kernel.org X-Gm-Message-State: AOJu0Yzyf+9caG0ROM/X6M2U8BmrJfQgTirZ+JbfUetgWr7Z4PW+enyr lXfD5xfopYX/kuIKnKv9H/DqLh03HHgysIhx1D/mlMBwns/8K/Holjiz X-Gm-Gg: AfdE7cnsT0wxg4rimnc5XiJ4EoWLHPJz+wduf9DO4VCy+Tm5Q44Knhfg56TCJ6xgs9e fvZJVXooPvJtsUQJdacYtmqAnmZ/aZXxwUw8UD8X5bZQzZ2o2fS+vUaspZnV7px+mQOCmQtYsGa 3AlXg59ubywxzF59Uhm4qbDfBjYytRITZtDGsUFYXZ0r/h23Tnt3I6UcvJmZhkHyXDcGmDZ333D qEZux1NdynfEm1jVdnbcMjbkz9qcB2NW1bZA0VNBS/LQaoJdq1jMufX0cSjeI6NdadM3RLbz+Og tPJrjyJNuSfd9LQ0I1JLKTjHEEbK3+ea7nIlV/YcJUhEOVYRgU7CyDcdqL4AWVuVE4iW3E0smi+ +sYpcilU7Y8bLmAF+VJ+ZaySu9eMa8mGLLK2mAUAXYLEWoiK+HDc2h7dGiyeIRVzIgevSL5EOq1 DOsF8Mhijebwbdal323xMhTHnivAn6zOxVbQNBlvKQxXeDTg== X-Received: by 2002:a05:6000:4010:b0:470:13e1:9908 with SMTP id ffacd0b85a97d-47df071c1b2mr4096508f8f.12.1783531182946; Wed, 08 Jul 2026 10:19:42 -0700 (PDT) Received: from pumpkin (host-92-21-50-228.as13285.net. [92.21.50.228]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47a9de1e736sm47829139f8f.7.2026.07.08.10.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 10:19:42 -0700 (PDT) Date: Wed, 8 Jul 2026 18:19:41 +0100 From: David Laight To: Cc: , , , , , Wenpeng Liang , Jason Gunthorpe , Leon Romanovsky , Xi Wang , Weihang Li , , Subject: Re: [PATCH v2] RDMA/hns: Fix arithmetic overflow in hns_roce_v2_set_hem() Message-ID: <20260708181941.1ad1e112@pumpkin> In-Reply-To: <20260708092146.3325855-1-Alexander.Chesnokov@kaspersky.com> References: <20260707140938.3106919-1-Alexander.Chesnokov@kaspersky.com> <20260708092146.3325855-1-Alexander.Chesnokov@kaspersky.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 8 Jul 2026 12:21:46 +0300 wrote: > From: Alexander Chesnokov > > If hop_num is 2 or 1, then the expressions like > i * chunk_ba_num + j are computed in 32-bit > arithmetic before being assigned to a u64 index field, > which can lead to overflow. When does the value overflow. Yes, the expression can overflow and the result is assigned to a 64bit variable, but I'd have testing this code would have showed the problem. So what is the customer visible impact? David > > Declare i, j and k as u64 so that the address index > arithmetic is performed in 64-bit. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: a81fba28136d ("RDMA/hns: Configure BT BA and BT attribute for the contexts in hip08") > Cc: stable@vger.kernel.org > Suggested-by: David Laight > Signed-off-by: Alexander Chesnokov > > --- > Changes in v2: > - Instead of casting the operands to u64, declare i, j and k as u64 > so the index arithmetic is performed in 64-bit (David Laight). > > v1: https://lore.kernel.org/linux-rdma/20260707140938.3106919-1-Alexander.Chesnokov@kaspersky.com/ > --- > drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c > index 1c180a6b1c07..3469a9a68d3b 100644 > --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c > +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c > @@ -4238,7 +4238,7 @@ static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev, > struct hns_roce_hem_mhop mhop; > struct hns_roce_hem *hem; > unsigned long mhop_obj = obj; > - int i, j, k; > + u64 i, j, k; > int ret = 0; > u64 hem_idx = 0; > u64 l1_idx = 0;