Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932728AbZJGLy5 (ORCPT ); Wed, 7 Oct 2009 07:54:57 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754031AbZJGLy4 (ORCPT ); Wed, 7 Oct 2009 07:54:56 -0400 Received: from smtp.ispras.ru ([83.149.198.201]:42388 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753998AbZJGLy4 (ORCPT ); Wed, 7 Oct 2009 07:54:56 -0400 From: Alexander Strakh Organization: ISP RAS To: Jaya Kumar , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] quickcam_messenger.c: possible buffer overflow while use strncat. Date: Wed, 7 Oct 2009 15:56:54 +0000 User-Agent: KMail/1.10.3 (Linux/2.6.27.29-0.1-default; KDE/4.1.3; x86_64; ; ) MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <200910071556.54534.strakh@ispras.ru> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1806 Lines: 43 In driver ./drivers/media/video/usbvideo/quickcam_messenger.c in line 91: 91 usb_make_path(dev, cam->input_physname, sizeof(cam- >input_physname)); After this line we use strncat: 92 strncat(cam->input_physname, "/input0", sizeof(cam- >input_physname)); where sizeof(cam->input_physname) returns length of cam->input_phisname without length for null-symbol. But this parameter must be - "maximum numbers of bytes to copy", i.e.: sizeof(cam->input_physname)-strlen(cam- >input_physname)-1. In this case, after call to usb_make_path the similar drivers use strlcat. Like in: drivers/hid/usbhid/hid-core.c: 1152 usb_make_path(dev, hid->phys, sizeof(hid->phys)); 1153 strlcat(hid->phys, "/input", sizeof(hid->phys)); Found by Linux Driver Verification Project. Use strlcat instead of strncat. Signed-off-by:Alexander Strakh --- diff --git a/./a/drivers/media/video/usbvideo/quickcam_messenger.c b/./b/drivers/media/video/usbvideo/quickcam_messenger.c index 803d3e4..c4d1b96 100644 --- a/./a/drivers/media/video/usbvideo/quickcam_messenger.c +++ b/./b/drivers/media/video/usbvideo/quickcam_messenger.c @@ -89,7 +89,7 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev) int error; usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname)); - strncat(cam->input_physname, "/input0", sizeof(cam->input_physname)); + strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname)); cam->input = input_dev = input_allocate_device(); if (!input_dev) { -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/