All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Urs Thuermann <urs.thuermann@volkswagen.de>,
	"David S. Miller" <davem@davemloft.net>
Subject: [55/91] can: add limit for nframes and clean up signed/unsigned variables
Date: Tue, 24 Aug 2010 15:42:17 -0700	[thread overview]
Message-ID: <20100824224216.788333308@clark.site> (raw)
In-Reply-To: <20100824224617.GA5440@kroah.com>

2.6.34-stable review patch.  If anyone has any objections, please let us know.

------------------


From: Oliver Hartkopp <socketcan@hartkopp.net>

[ Upstream commit 5b75c4973ce779520b9d1e392483207d6f842cde ]

This patch adds a limit for nframes as the number of frames in TX_SETUP and
RX_SETUP are derived from a single byte multiplex value by default.
Use-cases that would require to send/filter more than 256 CAN frames should
be implemented in userspace for complexity reasons anyway.

Additionally the assignments of unsigned values from userspace to signed
values in kernelspace and vice versa are fixed by using unsigned values in
kernelspace consistently.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Reported-by: Ben Hawkes <hawkes@google.com>
Acked-by: Urs Thuermann <urs.thuermann@volkswagen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 net/can/bcm.c |   41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -60,6 +60,13 @@
 #include <net/sock.h>
 #include <net/net_namespace.h>
 
+/*
+ * To send multiple CAN frame content within TX_SETUP or to filter
+ * CAN messages with multiplex index within RX_SETUP, the number of
+ * different filters is limited to 256 due to the one byte index value.
+ */
+#define MAX_NFRAMES 256
+
 /* use of last_frames[index].can_dlc */
 #define RX_RECV    0x40 /* received data for this element */
 #define RX_THR     0x80 /* element not been sent due to throttle feature */
@@ -89,16 +96,16 @@ struct bcm_op {
 	struct list_head list;
 	int ifindex;
 	canid_t can_id;
-	int flags;
+	u32 flags;
 	unsigned long frames_abs, frames_filtered;
 	struct timeval ival1, ival2;
 	struct hrtimer timer, thrtimer;
 	struct tasklet_struct tsklet, thrtsklet;
 	ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg;
 	int rx_ifindex;
-	int count;
-	int nframes;
-	int currframe;
+	u32 count;
+	u32 nframes;
+	u32 currframe;
 	struct can_frame *frames;
 	struct can_frame *last_frames;
 	struct can_frame sframe;
@@ -175,7 +182,7 @@ static int bcm_proc_show(struct seq_file
 
 		seq_printf(m, "rx_op: %03X %-5s ",
 				op->can_id, bcm_proc_getifname(ifname, op->ifindex));
-		seq_printf(m, "[%d]%c ", op->nframes,
+		seq_printf(m, "[%u]%c ", op->nframes,
 				(op->flags & RX_CHECK_DLC)?'d':' ');
 		if (op->kt_ival1.tv64)
 			seq_printf(m, "timeo=%lld ",
@@ -198,7 +205,7 @@ static int bcm_proc_show(struct seq_file
 
 	list_for_each_entry(op, &bo->tx_ops, list) {
 
-		seq_printf(m, "tx_op: %03X %s [%d] ",
+		seq_printf(m, "tx_op: %03X %s [%u] ",
 				op->can_id,
 				bcm_proc_getifname(ifname, op->ifindex),
 				op->nframes);
@@ -283,7 +290,7 @@ static void bcm_send_to_user(struct bcm_
 	struct can_frame *firstframe;
 	struct sockaddr_can *addr;
 	struct sock *sk = op->sk;
-	int datalen = head->nframes * CFSIZ;
+	unsigned int datalen = head->nframes * CFSIZ;
 	int err;
 
 	skb = alloc_skb(sizeof(*head) + datalen, gfp_any());
@@ -468,7 +475,7 @@ rx_changed_settime:
  * bcm_rx_cmp_to_index - (bit)compares the currently received data to formerly
  *                       received data stored in op->last_frames[]
  */
-static void bcm_rx_cmp_to_index(struct bcm_op *op, int index,
+static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index,
 				const struct can_frame *rxdata)
 {
 	/*
@@ -554,7 +561,8 @@ static enum hrtimer_restart bcm_rx_timeo
 /*
  * bcm_rx_do_flush - helper for bcm_rx_thr_flush
  */
-static inline int bcm_rx_do_flush(struct bcm_op *op, int update, int index)
+static inline int bcm_rx_do_flush(struct bcm_op *op, int update,
+				  unsigned int index)
 {
 	if ((op->last_frames) && (op->last_frames[index].can_dlc & RX_THR)) {
 		if (update)
@@ -575,7 +583,7 @@ static int bcm_rx_thr_flush(struct bcm_o
 	int updated = 0;
 
 	if (op->nframes > 1) {
-		int i;
+		unsigned int i;
 
 		/* for MUX filter we start at index 1 */
 		for (i = 1; i < op->nframes; i++)
@@ -624,7 +632,7 @@ static void bcm_rx_handler(struct sk_buf
 {
 	struct bcm_op *op = (struct bcm_op *)data;
 	const struct can_frame *rxframe = (struct can_frame *)skb->data;
-	int i;
+	unsigned int i;
 
 	/* disable timeout */
 	hrtimer_cancel(&op->timer);
@@ -824,14 +832,15 @@ static int bcm_tx_setup(struct bcm_msg_h
 {
 	struct bcm_sock *bo = bcm_sk(sk);
 	struct bcm_op *op;
-	int i, err;
+	unsigned int i;
+	int err;
 
 	/* we need a real device to send frames */
 	if (!ifindex)
 		return -ENODEV;
 
-	/* we need at least one can_frame */
-	if (msg_head->nframes < 1)
+	/* check nframes boundaries - we need at least one can_frame */
+	if (msg_head->nframes < 1 || msg_head->nframes > MAX_NFRAMES)
 		return -EINVAL;
 
 	/* check the given can_id */
@@ -995,6 +1004,10 @@ static int bcm_rx_setup(struct bcm_msg_h
 		msg_head->nframes = 0;
 	}
 
+	/* the first element contains the mux-mask => MAX_NFRAMES + 1  */
+	if (msg_head->nframes > MAX_NFRAMES + 1)
+		return -EINVAL;
+
 	if ((msg_head->flags & RX_RTR_FRAME) &&
 	    ((msg_head->nframes != 1) ||
 	     (!(msg_head->can_id & CAN_RTR_FLAG))))



  parent reply	other threads:[~2010-08-24 23:31 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-24 22:46 [00/91] 2.6.34.6-stable review Greg KH
2010-08-24 22:41 ` [01/91] memstick: init sysfs attributes Greg KH
2010-08-24 22:41 ` [02/91] memstick: fix hangs on unexpected device removal in mspro_blk Greg KH
2010-08-24 22:41 ` [03/91] ASoC: Fix inverted mute controls for WM8580 Greg KH
2010-08-24 22:41 ` [04/91] ASoC: Remove DSP mode support for WM8776 Greg KH
2010-08-24 22:41 ` [05/91] ASoC: register cache should be 1 byte aligned for 1 byte long register Greg KH
2010-08-24 22:41 ` [06/91] regulator: Default GPIO controlled WM8994 regulators to disabled Greg KH
2010-08-24 22:41 ` [07/91] ALSA: riptide - Fix detection / load of firmware files Greg KH
2010-08-24 22:41 ` [08/91] ALSA: emu10k1 - delay the PCM interrupts (add pcm_irq_delay parameter) Greg KH
2010-08-24 22:41 ` [09/91] ALSA: hda - Fix missing stream for second ADC on Realtek ALC260 HDA codec Greg KH
2010-08-24 22:41 ` [10/91] ALSA: hda - Add quirk for Dell Vostro 1220 Greg KH
2010-08-24 22:41 ` [11/91] ocfs2: do not overwrite error codes in ocfs2_init_acl Greg KH
2010-08-24 22:41 ` [12/91] ocfs2/dlm: fix a dead lock Greg KH
2010-08-24 22:41 ` [13/91] ocfs2 fix o2dlm dlm run purgelist (rev 3) Greg KH
2010-08-24 22:41 ` [14/91] ocfs2: Count more refcount records in file system fragmentation Greg KH
2010-08-24 22:41 ` [15/91] ocfs2/dlm: avoid incorrect bit set in refmap on recovery master Greg KH
2010-08-24 22:41 ` [16/91] ocfs2/dlm: remove potential deadlock -V3 Greg KH
2010-08-24 22:41 ` [17/91] wl1251: fix trigger scan timeout usage Greg KH
2010-08-24 22:41 ` [18/91] nilfs2: fix list corruption after ifile creation failure Greg KH
2010-08-24 22:41 ` [19/91] tracing: Fix an unallocated memory access in function_graph Greg KH
2010-08-24 22:41 ` [20/91] tracing: Fix ring_buffer_read_page reading out of page boundary Greg KH
2010-08-24 22:41 ` [21/91] cfg80211: fix locking in action frame TX Greg KH
2010-08-24 22:41 ` [22/91] platform/x86: move rfkill for Dell Mini 1012 to compal-laptop Greg KH
2010-08-24 22:41 ` [23/91] x86, hotplug: Serialize CPU hotplug to avoid bringup concurrency issues Greg KH
2010-08-24 22:41 ` [24/91] x86, apic: Fix apic=debug boot crash Greg KH
2010-08-24 22:41   ` Greg KH
2010-08-24 22:41 ` [25/91] Fix the nested PR lock calling issue in ACL Greg KH
2010-08-24 22:41 ` [26/91] drm/radeon/kms: add additional quirk for Acer rv620 laptop Greg KH
2010-08-24 22:41 ` [27/91] hwmon: (pc87360) Fix device resource declaration Greg KH
2010-08-24 22:41 ` [28/91] ARM: Tighten check for allowable CPSR values Greg KH
2010-08-24 22:41 ` [29/91] ARM: Fix gen_nand probe structures contents Greg KH
2010-08-24 22:41 ` [30/91] BFIN: " Greg KH
2010-08-24 22:41 ` [31/91] nfs: Add "lookupcache" to displayed mount options Greg KH
2010-08-24 22:41 ` [32/91] ath5k: disable ASPM L0s for all cards Greg KH
2010-08-24 22:41 ` [33/91] pxa3xx: fix ns2cycle equation Greg KH
2010-08-24 22:41 ` [34/91] matroxfb: fix incorrect use of memcpy_toio() Greg KH
2010-08-24 22:41 ` [35/91] drm/i915: fixup pageflip ringbuffer commands for i8xx Greg KH
2010-08-24 22:41 ` [36/91] drm/i915: i8xx also doesnt like multiple oustanding pageflips Greg KH
2010-08-24 22:41 ` [37/91] drm/i915/edp: Flush the write before waiting for PLLs Greg KH
2010-08-24 22:42 ` [38/91] dm mpath: fix NULL pointer dereference when path parameters missing Greg KH
2010-08-24 22:42 ` [39/91] dm snapshot: iterate origin and cow devices Greg KH
2010-08-24 22:42 ` [40/91] dm snapshot: test chunk size against both origin and snapshot Greg KH
2010-08-24 22:42 ` [41/91] dm: prevent access to md being deleted Greg KH
2010-08-24 22:42 ` [42/91] dm ioctl: release _hash_lock between devices in remove_all Greg KH
2010-08-24 22:42 ` [43/91] mm: make the vma list be doubly linked Greg KH
2010-08-24 22:42 ` [44/91] mm: make the mlock() stack guard page checks stricter Greg KH
2010-08-24 22:42 ` [45/91] mm: make stack guard page logic use vm_prev pointer Greg KH
2010-08-24 22:42 ` [46/91] x86, asm: Clean up and simplify set_64bit() Greg KH
2010-08-24 22:42 ` [47/91] slab: fix object alignment Greg KH
2010-08-24 22:42 ` [48/91] sparc64: Fix atomic64_t routine return values Greg KH
2010-08-24 22:42 ` [49/91] sparc64: Add missing ID to parport probing code Greg KH
2010-08-24 22:42 ` [50/91] sparc64: Fix rwsem constant bug leading to hangs Greg KH
2010-08-24 22:42 ` [51/91] bridge: add rcu_read_lock on transmit Greg KH
2010-08-24 22:42 ` [52/91] tcp: cookie transactions setsockopt memory leak Greg KH
2010-08-24 22:42 ` [53/91] bridge: Fix skb leak when multicast parsing fails on TX Greg KH
2010-08-24 22:42 ` [54/91] act_nat: the checksum of ICMP doesnt have pseudo header Greg KH
2010-08-24 22:42 ` Greg KH [this message]
2010-08-24 22:42 ` [56/91] net: dev_forward_skb should call nf_reset Greg KH
2010-08-24 22:42 ` [57/91] isdn: fix information leak Greg KH
2010-08-24 22:42 ` [58/91] net: Fix napi_gro_frags vs netpoll path Greg KH
2010-08-24 22:42 ` [59/91] net: Fix a memmove bug in dev_gro_receive() Greg KH
2010-08-24 22:42 ` [60/91] pkt_sched: Fix sch_sfq vs tcf_bind_filter oops Greg KH
2010-08-24 22:42 ` [61/91] pkt_sched: Fix sch_sfq vs tc_modify_qdisc oops Greg KH
2010-08-24 22:42 ` [62/91] vmscan: raise the bar to PAGEOUT_IO_SYNC stalls Greg KH
2010-08-24 22:42 ` [63/91] pcmcia: avoid buffer overflow in pcmcia_setup_isa_irq Greg KH
2010-08-24 22:42 ` [64/91] isdn/gigaset: reduce syslog spam Greg KH
2010-08-24 22:42 ` [65/91] isdn: gigaset: add missing unlock Greg KH
2010-08-24 22:42 ` [66/91] Oprofile: Change CPUIDS from decimal to hex, and add some comments Greg KH
2010-08-24 22:42 ` [67/91] oprofile: add support for Intel processor model 30 Greg KH
2010-08-24 22:42 ` [68/91] e1000e: disable ASPM L1 on 82573 Greg KH
2010-08-24 22:42 ` [69/91] e1000e: dont check for alternate MAC addr on parts that dont support it Greg KH
2010-08-24 22:42 ` [70/91] fixes for using make 3.82 Greg KH
2010-08-24 22:42 ` [71/91] ALSA: intel8x0: Mute External Amplifier by default for ThinkPad X31 Greg KH
2010-08-24 22:42 ` [72/91] netlink: fix compat recvmsg Greg KH
2010-08-24 22:42 ` [73/91] drm/radeon/kms: dont enable MSIs on AGP boards Greg KH
2010-08-24 22:42 ` [74/91] drm/radeon/kms: fix typo in radeon_compute_pll_gain Greg KH
2010-08-24 22:42 ` [75/91] drm/radeon/kms/DCE3+: switch pads to ddc mode when going i2c Greg KH
2010-08-24 22:42 ` [76/91] drm/radeon/kms: fix sideport detection on newer rs880 boards Greg KH
2010-08-24 22:42 ` [77/91] drm/radeon/kms: fix GTT/VRAM overlapping test Greg KH
2010-08-24 22:42 ` [78/91] drm: stop information leak of old kernel stack Greg KH
2010-08-24 22:42 ` [79/91] powerpc: Fix typo in uImage target Greg KH
2010-08-24 22:42 ` [80/91] powerpc: Initialise paca->kstack before early_setup_secondary Greg KH
2010-08-24 22:42 ` [81/91] USB: option: add Celot CT-650 Greg KH
2010-08-24 22:42 ` [82/91] USB: add device IDs for igotu to navman Greg KH
2010-08-24 22:42 ` [83/91] USB: pl2303: New vendor and product id Greg KH
2010-08-24 22:42 ` [84/91] USB: CP210x Fix Break On/Off Greg KH
2010-08-24 22:42 ` [85/91] USB: ftdi_sio: fix endianess of max packet size Greg KH
2010-08-24 22:42 ` [86/91] USB: io_ti: check firmware version before updating Greg KH
2010-08-24 22:42 ` [87/91] USB: xhci: Remove buggy assignment in next_trb() Greg KH
2010-08-24 22:42 ` [88/91] USB: ftdi_sio: Add ID for Ionics PlugComputer Greg KH
2010-08-24 22:42 ` [89/91] USB: ftdi_sio: add product ID for Lenz LI-USB Greg KH
2010-08-24 22:42 ` [90/91] tracing: Fix timer tracing Greg KH
2010-08-24 22:42 ` [91/91] x86, apic: ack all pending irqs when crashed/on kexec Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100824224216.788333308@clark.site \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=urs.thuermann@volkswagen.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.