From nobody Tue Nov 26 17:38:32 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 1C609187342 for ; Wed, 16 Oct 2024 17:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729099639; cv=none; b=shOyHgfjSWmXt8hGH5N8kWXYz40Ze3+AUwBJ0nnK40OcbMhId9/NhRfn2Ab53DPqiAGXrBo3E02M9K2FAtaGfcKIIblrzfHlP22Fd6mGNxha/7dskBG66jgbC4acxzgBG00y5jNgpfBnqI7skTi9VVAgsJPUcGSA/ad/2aKa/jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729099639; c=relaxed/simple; bh=fzLmjTYv50o4SO1uhihHDhxEFGjJN+CktGLAz3N15Yg=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=QS6l5O3nLCGdr4RFFM1j2aErZ5Asp6Ix9u/rlfJpOV9h18NROdWpxM25TNVecZqavLleGpZYJxvX80OrRaT+JejeLWgQpivyv7xihjFt+1OxV7iIwLgWC5VKXYvu5F7rL7jnuCxICbU/mL9k0HortBOV/FYjZmTfXCf+vaGQZEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XHy9yOHP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XHy9yOHP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729099636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=mm9TWMoNEKmC5/H75qa50GgVA8uFrq/T9r2miRc0UHg=; b=XHy9yOHPLqIiocxvFjK6TfjEy8wBdj6JDs10vNRPgWxzPQoDA7tvjoLPGQlMHx+YU/Zd6e 2THAD6/wZ06L/KOMUiz9PzIXA424vhQCfwawx9ulbKzgyAeTFfUpLGiHH+ml9h2ryBgxnH 983M4vLbv/gjwHk1q59+kY3feESz+7k= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-SqEBuLPuN4Kr3o0MLKL2tQ-1; Wed, 16 Oct 2024 13:27:15 -0400 X-MC-Unique: SqEBuLPuN4Kr3o0MLKL2tQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d67fe93c6so3443f8f.0 for ; Wed, 16 Oct 2024 10:27:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729099633; x=1729704433; 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=mm9TWMoNEKmC5/H75qa50GgVA8uFrq/T9r2miRc0UHg=; b=TnhotYDtfuNFLdaSSwQH+AIxIEPAvrZbcOKiMKZZrQPZerq0UlxGiiycZuwEeYDQEt +k7lWuNF0b26xoJJQZvMM6tgpkSlr4QGU7mvv+eVgRCylDR0+6Y75G6GBCFMI/TCdWRu tZI3mUYRBd63y60ovSOp2xeawWxoDEzFJhQ3JSgH9Bqw1WpjBXpC6ZnVeIozHBrAkCm4 NQJybvMeSPL9/kSUzT7AafU3cZNe2u6VGzWrWcXDujOcv8vtPFPV8ec5p3W4/GbARcvY d756ORoqC8mPrZWOrX3hA4cT9vL4dmCH4tdz1Z8pNrzELIP+NUhOWy2xfpJD1nmiMblf WFxA== X-Gm-Message-State: AOJu0YxfHGp/tmg+nJPQ6pJxn/sMtjejBELfwPQdoBrpGkSxrhzmT9as 6kEJJlWqAJmRLlbRzg1kX/FcSryrdub+lJWbTUaSY4TOa2I/WHElYN5By149lZmep5gCwAXa+fg MAEi5jM/uYROMYRbWw0ffNiE2FylKCheij2ERUnGug56Ma3I6TV8lM1ltiCuvPVbYWo4I+Hxlz9 yNq2CkrvW04vOnzx29rS/G73caORY1ztogiEHD59g= X-Received: by 2002:a5d:6703:0:b0:37d:4dd5:220f with SMTP id ffacd0b85a97d-37d551fba84mr12804143f8f.26.1729099633430; Wed, 16 Oct 2024 10:27:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/2kqVFlb2DtsXVfaMvtF8YMmP+fSHaEOFSLeUgaj7tCoSNI0g7YeZxeafsJNPE7r4ODqUXg== X-Received: by 2002:a5d:6703:0:b0:37d:4dd5:220f with SMTP id ffacd0b85a97d-37d551fba84mr12804117f8f.26.1729099632938; Wed, 16 Oct 2024 10:27:12 -0700 (PDT) Received: from redhat.com ([2a02:14f:174:b9f1:592:644a:6aa0:615c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc445fesm4832875f8f.113.2024.10.16.10.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 10:27:12 -0700 (PDT) Date: Wed, 16 Oct 2024 13:27:07 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "Colin King (gmail)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, netdev@vger.kernel.org Subject: [PATCH] virtio_net: fix integer overflow in stats Message-ID: <53e2bd6728136d5916e384a7840e5dc7eebff832.1729099611.git.mst@redhat.com> 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 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Static analysis on linux-next has detected the following issue in function virtnet_stats_ctx_init, in drivers/net/virtio_net.c : if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_CVQ) { queue_type =3D VIRTNET_Q_TYPE_CQ; ctx->bitmap[queue_type] |=3D VIRTIO_NET_STATS_TYPE_CVQ; ctx->desc_num[queue_type] +=3D ARRAY_SIZE(virtnet_stats_cvq= _desc); ctx->size[queue_type] +=3D sizeof(struct virtio_net_sta= ts_cvq); } ctx->bitmap is declared as a u32 however it is being bit-wise or'd with VIRTIO_NET_STATS_TYPE_CVQ and this is defined as 1 << 32: include/uapi/linux/virtio_net.h:#define VIRTIO_NET_STATS_TYPE_CVQ (1ULL << = 32) ..and hence the bit-wise or operation won't set any bits in ctx->bitmap because 1ULL < 32 is too wide for a u32. In fact, the field is read into a u64: u64 offset, bitmap; .... bitmap =3D ctx->bitmap[queue_type]; so to fix, it is enough to make bitmap an array of u64. Fixes: 941168f8b40e5 ("virtio_net: support device stats") Reported-by: "Colin King (gmail)" Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang Reviewed-by: Stefano Garzarella --- drivers/net/virtio_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c6af18948092..b950d24b1ffa 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -4112,7 +4112,7 @@ struct virtnet_stats_ctx { u32 desc_num[3]; =20 /* The actual supported stat types. */ - u32 bitmap[3]; + u64 bitmap[3]; =20 /* Used to calculate the reply buffer size. */ u32 size[3]; --=20 MST