Skip to content

Commit

Permalink
can: raw: use temp variable instead of rolling back config
Browse files Browse the repository at this point in the history
Introduce a temporary variable to check for an invalid configuration
attempt from user space. Before this patch the value was copied to
the real config variable and rolled back in the case of an error.

Suggested-by: Marc Kleine-Budde <[email protected]>
Signed-off-by: Oliver Hartkopp <[email protected]>
Link: https://lore.kernel.org/all/[email protected]
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
hartkopp authored and marckleinebudde committed Feb 8, 2023
1 parent e6ebe6c commit f2f527d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
struct can_filter sfilter; /* single filter */
struct net_device *dev = NULL;
can_err_mask_t err_mask = 0;
int fd_frames;
int count = 0;
int err = 0;

Expand Down Expand Up @@ -664,17 +665,17 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
break;

case CAN_RAW_FD_FRAMES:
if (optlen != sizeof(ro->fd_frames))
if (optlen != sizeof(fd_frames))
return -EINVAL;

if (copy_from_sockptr(&ro->fd_frames, optval, optlen))
if (copy_from_sockptr(&fd_frames, optval, optlen))
return -EFAULT;

/* Enabling CAN XL includes CAN FD */
if (ro->xl_frames && !ro->fd_frames) {
ro->fd_frames = ro->xl_frames;
if (ro->xl_frames && !fd_frames)
return -EINVAL;
}

ro->fd_frames = fd_frames;
break;

case CAN_RAW_XL_FRAMES:
Expand Down

0 comments on commit f2f527d

Please sign in to comment.