[linux-next:master 13949/14198] drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1133 amdgpu_discovery_reg_base_init() error: testing array offset 'adev->vcn.num_vcn_inst' after use.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[ This is one of those weird things where the kbuild bot sends the
  warning to -mm instead of the AMD list.  It will likely try send a
  duplicate warning to the AMD list in a few days.  I would have sent
  this warning in a couple hours from my devel system as well. -dan]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   d3fde8ff50ab265749704bd7fbcf70d35235421f
commit: a0ccc717c4ab3ef572f023fdceffb4b6df496a0d [13949/14198] drm/amdgpu/discovery: validate VCN and SDMA instances
config: arc-randconfig-m031-20220524 (https://download.01.org/0day-ci/archive/20220528/202205280055.X7671nNw-lkp@xxxxxxxxx/config)
compiler: arceb-elf-gcc (GCC) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1133 amdgpu_discovery_reg_base_init() error: testing array offset 'adev->vcn.num_vcn_inst' after use.

Old smatch warnings:
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1454 amdgpu_discovery_get_vcn_info() error: buffer overflow 'adev->vcn.vcn_codec_disable_mask' 2 <= 3

vim +1133 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c

e24d0e91b336762 Alex Deucher    2022-03-30  1065  static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1066  {
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1067  	struct binary_header *bhdr;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1068  	struct ip_discovery_header *ihdr;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1069  	struct die_header *dhdr;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1070  	struct ip *ip;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1071  	uint16_t die_offset;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1072  	uint16_t ip_offset;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1073  	uint16_t num_dies;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1074  	uint16_t num_ips;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1075  	uint8_t num_base_address;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1076  	int hw_ip;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1077  	int i, j, k;
dffa11b4f74b157 Monk Liu        2020-03-04  1078  	int r;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1079  
dffa11b4f74b157 Monk Liu        2020-03-04  1080  	r = amdgpu_discovery_init(adev);
dffa11b4f74b157 Monk Liu        2020-03-04  1081  	if (r) {
dffa11b4f74b157 Monk Liu        2020-03-04  1082  		DRM_ERROR("amdgpu_discovery_init failed\n");
dffa11b4f74b157 Monk Liu        2020-03-04  1083  		return r;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1084  	}
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1085  
72de33f8f7ba0f4 Alex Deucher    2020-07-29  1086  	bhdr = (struct binary_header *)adev->mman.discovery_bin;
72de33f8f7ba0f4 Alex Deucher    2020-07-29  1087  	ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin +
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1088  			le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset));
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1089  	num_dies = le16_to_cpu(ihdr->num_dies);
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1090  
437298b833996de Xiaojie Yuan    2019-03-27  1091  	DRM_DEBUG("number of dies: %d\n", num_dies);
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1092  
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1093  	for (i = 0; i < num_dies; i++) {
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1094  		die_offset = le16_to_cpu(ihdr->die_info[i].die_offset);
72de33f8f7ba0f4 Alex Deucher    2020-07-29  1095  		dhdr = (struct die_header *)(adev->mman.discovery_bin + die_offset);
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1096  		num_ips = le16_to_cpu(dhdr->num_ips);
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1097  		ip_offset = die_offset + sizeof(*dhdr);
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1098  
437298b833996de Xiaojie Yuan    2019-03-27  1099  		if (le16_to_cpu(dhdr->die_id) != i) {
437298b833996de Xiaojie Yuan    2019-03-27  1100  			DRM_ERROR("invalid die id %d, expected %d\n",
437298b833996de Xiaojie Yuan    2019-03-27  1101  					le16_to_cpu(dhdr->die_id), i);
437298b833996de Xiaojie Yuan    2019-03-27  1102  			return -EINVAL;
437298b833996de Xiaojie Yuan    2019-03-27  1103  		}
437298b833996de Xiaojie Yuan    2019-03-27  1104  
437298b833996de Xiaojie Yuan    2019-03-27  1105  		DRM_DEBUG("number of hardware IPs on die%d: %d\n",
437298b833996de Xiaojie Yuan    2019-03-27  1106  				le16_to_cpu(dhdr->die_id), num_ips);
437298b833996de Xiaojie Yuan    2019-03-27  1107  
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1108  		for (j = 0; j < num_ips; j++) {
72de33f8f7ba0f4 Alex Deucher    2020-07-29  1109  			ip = (struct ip *)(adev->mman.discovery_bin + ip_offset);
5039f5298880f7a Ernst Sjöstrand 2021-09-26  1110  
5039f5298880f7a Ernst Sjöstrand 2021-09-26  1111  			if (amdgpu_discovery_validate_ip(ip))
5039f5298880f7a Ernst Sjöstrand 2021-09-26  1112  				goto next_ip;
5039f5298880f7a Ernst Sjöstrand 2021-09-26  1113  
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1114  			num_base_address = ip->num_base_address;
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1115  
437298b833996de Xiaojie Yuan    2019-03-27  1116  			DRM_DEBUG("%s(%d) #%d v%d.%d.%d:\n",
437298b833996de Xiaojie Yuan    2019-03-27  1117  				  hw_id_names[le16_to_cpu(ip->hw_id)],
437298b833996de Xiaojie Yuan    2019-03-27  1118  				  le16_to_cpu(ip->hw_id),
437298b833996de Xiaojie Yuan    2019-03-27  1119  				  ip->number_instance,
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1120  				  ip->major, ip->minor,
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1121  				  ip->revision);
f39f5bb1c9d68d5 Xiaojie Yuan    2019-06-20  1122  
baf3f8f37406257 Alex Deucher    2021-11-30  1123  			if (le16_to_cpu(ip->hw_id) == VCN_HWID) {
c40bdfb2ffa4cf1 Leslie Shi      2021-12-08  1124  				/* Bit [5:0]: original revision value
baf3f8f37406257 Alex Deucher    2021-11-30  1125  				 * Bit [7:6]: en/decode capability:
baf3f8f37406257 Alex Deucher    2021-11-30  1126  				 *     0b00 : VCN function normally
baf3f8f37406257 Alex Deucher    2021-11-30  1127  				 *     0b10 : encode is disabled
baf3f8f37406257 Alex Deucher    2021-11-30  1128  				 *     0b01 : decode is disabled
baf3f8f37406257 Alex Deucher    2021-11-30  1129  				 */
c40bdfb2ffa4cf1 Leslie Shi      2021-12-08  1130  				adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
                                                                                                     ^^^^^^^^^^^^^^^^^^^^^^
If adev->vcn.num_vcn_inst == AMDGPU_MAX_VCN_INSTANCES then this will
corrupt memory.

c40bdfb2ffa4cf1 Leslie Shi      2021-12-08  1131  					ip->revision & 0xc0;
baf3f8f37406257 Alex Deucher    2021-11-30  1132  				ip->revision &= ~0xc0;
a0ccc717c4ab3ef Alex Deucher    2022-05-16 @1133  				if (adev->vcn.num_vcn_inst < AMDGPU_MAX_VCN_INSTANCES)
                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Checked too late.

7cbe08a930a132d Alex Deucher    2021-08-09  1134  					adev->vcn.num_vcn_inst++;
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1135  				else
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1136  					dev_err(adev->dev, "Too many VCN instances: %d vs %d\n",
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1137  						adev->vcn.num_vcn_inst + 1,
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1138  						AMDGPU_MAX_VCN_INSTANCES);
baf3f8f37406257 Alex Deucher    2021-11-30  1139  			}
5c3720be7d46581 Alex Deucher    2021-08-09  1140  			if (le16_to_cpu(ip->hw_id) == SDMA0_HWID ||
5c3720be7d46581 Alex Deucher    2021-08-09  1141  			    le16_to_cpu(ip->hw_id) == SDMA1_HWID ||
5c3720be7d46581 Alex Deucher    2021-08-09  1142  			    le16_to_cpu(ip->hw_id) == SDMA2_HWID ||
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1143  			    le16_to_cpu(ip->hw_id) == SDMA3_HWID) {
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1144  				if (adev->sdma.num_instances < AMDGPU_MAX_SDMA_INSTANCES)
5c3720be7d46581 Alex Deucher    2021-08-09  1145  					adev->sdma.num_instances++;
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1146  				else
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1147  					dev_err(adev->dev, "Too many SDMA instances: %d vs %d\n",
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1148  						adev->sdma.num_instances + 1,
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1149  						AMDGPU_MAX_SDMA_INSTANCES);
a0ccc717c4ab3ef Alex Deucher    2022-05-16  1150  			}
7cbe08a930a132d Alex Deucher    2021-08-09  1151  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux