Skip to content

Commit dd925db

Browse files
committed
firmware: arm_ffa: Fix a possible ffa_linux_errmap buffer overflow
The ffa_linux_errmap buffer access index is supposed to range from 0-8 but it ranges from 1-9 instead. It reads one element out of bounds. It also changes the success into -EINVAL though ffa_to_linux_errno is never used in case of success, it is expected to work for success case too. It is slightly confusing code as the negative of the error code is used as index to the buffer. Fix it by negating it at the start and make it more readable. Link: https://lore.kernel.org/r/20210707134739.1869481-1-sudeep.holla@arm.com Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent ba684a3 commit dd925db

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/firmware/arm_ffa/driver.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ static const int ffa_linux_errmap[] = {
149149

150150
static inline int ffa_to_linux_errno(int errno)
151151
{
152-
if (errno < FFA_RET_SUCCESS && errno >= -ARRAY_SIZE(ffa_linux_errmap))
153-
return ffa_linux_errmap[-errno];
152+
int err_idx = -errno;
153+
154+
if (err_idx >= 0 && err_idx < ARRAY_SIZE(ffa_linux_errmap))
155+
return ffa_linux_errmap[err_idx];
154156
return -EINVAL;
155157
}
156158

0 commit comments

Comments
 (0)