From patchwork Wed Jun 19 19:42:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13704485 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17FD2158D98; Wed, 19 Jun 2024 19:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718826183; cv=none; b=QBzm6423flRZwF8RlNkLpea3xzDIdTfjL8mWstQTfuyYZ2xJSEosERZRyW4OVQmatXzREYmbDxNGpuU7elanZISgKW5GfZHT1tAJ0730qK49ZNQb17yqwMvE6b5b4rIhUuDbsYd3XQU5d9o5WDxF3v3smqxusGgjj90QVHY9OtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718826183; c=relaxed/simple; bh=w6bEo4hzeOHVJnJPuko3xutI/ZQH3eACUV0/Ggy3JqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bz5EjWStwK0gG/EQ8PZWHvSGofrjILAS1UqFL3elI+9AQC4btvKpoiyzDAvhd5trCF6QpiNgNh90iYLHrCpsZJTgeRvnzoY6VHmZIoiPd1aQNvD4V1L6fNkCAHmFM1mvC7X5rzsGu9X1xLQjdhVEaFdD6Fd/z1TfHd234FJ3LLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g3QjZnFe; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g3QjZnFe" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-57d0f929f79so55667a12.2; Wed, 19 Jun 2024 12:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718826180; x=1719430980; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FGRH5fHTr0h6rLCcNKkztnyBTw6+o9c4VOS4ZsV7VSU=; b=g3QjZnFeyWOSCR1hLdmsHeCtGo1ZvZ/BBnGMhenmZU43UJ4YoEtztiTn56Suom2k8l qLij7GRrpptY+7iRHAg4dyI9Q2TudVKdP7hunmN/N1bpMVJV53Krs1KxoL/0qPAuRf4W yEzP1JYmIAU5fD/oLcpbaZsTHGJCPvHzYeY0qi459t5sd6x9hG0OGORNWf+FlrhYFSDx s8uqqLD7DLHyOQ9XLSzeQHBAawTFoWVsmMllwSMHfjX4TPPO20LLXLqJY9XwSrR+tmeW AKl390LVaOC1tg78LiEpaPcuSdXNKDTwKE3WnImxtP/hI7aoUhdA7fg9VewcfcUxj16j NJ2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718826180; x=1719430980; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FGRH5fHTr0h6rLCcNKkztnyBTw6+o9c4VOS4ZsV7VSU=; b=Tt+ukOAUKK9790DSHiiZ44OB/mPMqt1Fc+eKDtbfe2lN7CroKZiEKyfoLbGXHMpCIC AV2qCp81PSjMsOljy8Kgb2MZU3Gefawh1kX+0RkIuFYhE3nCsPoiFTePEPGSdC96nfZ8 WZsslDZuKYSJs1JBaNpblQrUb+VQX0H5iMIceX3mmZ5805irIQwW9oMV2ziHI0fopMlq 9mazc/oZOLsbhfJ+mH0zXOhN3+f3zFjs1ZP8R9H+/maPwdvAQa+t6gxnbiSQqSFlYn54 1cPqD0lqJvP/xwnKl8rTUxl4TTnSB6R6Q5hNWJr6vcfWpDGb+1Sz9/9NY6uV7NGV53Ku OOcg== X-Forwarded-Encrypted: i=1; AJvYcCVfe19N6ElRIvejCtkaVLfLU3yjEBhApT3FEcF8jpKXNk7xMCLyiIcq43b3HItnRbGKIbddjmXsjLcrq99UjtI09bOAJzpFGv8UPvjVnLVoInVp3aB9PSuHHeRiGQOyNq8BpTyzX53JYD10IXix X-Gm-Message-State: AOJu0YzdhjBSwdnQYtlfxhhtRFkLBkxVo5G8/Ozw3AuVnHqgs7l27GBn kLrsNXqTEh+9tPOro9Wnv38ho8NknEW9EMi88wRFGuUTi+YAB46a X-Google-Smtp-Source: AGHT+IFfwIwY8aUbglen02/7gMx0S5ySU/sjV166DZHYCMacKsieRX+OujYltXbbqyPFCuD5AJ+O+w== X-Received: by 2002:a17:906:13d8:b0:a6f:4dfc:5f31 with SMTP id a640c23a62f3a-a6fab7d0af8mr201161166b.73.1718826180108; Wed, 19 Jun 2024 12:43:00 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-103.cable.dynamic.surfer.at. [84.115.213.103]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56da3385sm688365766b.24.2024.06.19.12.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 12:42:59 -0700 (PDT) From: Javier Carrasco Date: Wed, 19 Jun 2024 21:42:44 +0200 Subject: [PATCH v2 1/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240619-garmin_gps_counted_by-v2-1-f82f10ebbf28@gmail.com> References: <20240619-garmin_gps_counted_by-v2-0-f82f10ebbf28@gmail.com> In-Reply-To: <20240619-garmin_gps_counted_by-v2-0-f82f10ebbf28@gmail.com> To: Johan Hovold , Greg Kroah-Hartman , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1718826176; l=856; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=w6bEo4hzeOHVJnJPuko3xutI/ZQH3eACUV0/Ggy3JqQ=; b=KCgAjoBMltppuesL5JTI8/GbbOBI3JwTGmrsYCJP321E9yYWzlqSoQ1tDb/dQFHYwd2muWiuB uM7gGyNDT0/A5kOYPldbIjrPvUvRLeyUpOu+tQVMjcD28EtE6/8K9hj X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Use the __counted_by compiler attribute for the data[] flexible array member to improve the results of array bound sanitizers. Reviewed-by: Nathan Chancellor Signed-off-by: Javier Carrasco Reviewed-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/usb/serial/garmin_gps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 670e942fdaaa..57df6ad183ff 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -104,7 +104,7 @@ struct garmin_packet { int seq; /* the real size of the data array, always > 0 */ int size; - __u8 data[]; + __u8 data[] __counted_by(size); }; /* structure used to keep the current state of the driver */ From patchwork Wed Jun 19 19:42:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13704486 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6422B158DD9; Wed, 19 Jun 2024 19:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718826185; cv=none; b=uPn+o7tFxRZxr8JhL71G6BxLhd8/9aRd8g3U9ikZ9DI7PSh008hwuS1kbNcbCAJulVJMAEdN4PyQvi4ghK13mUfetbvxhROC4EzlWRuaN3BQq6QOI1h5VYXOeW4BsfMfftS6w1peE3XYlHylUcUIcw4rZzKEkauADiOVKmZ6cgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718826185; c=relaxed/simple; bh=qCJk9bWEc+/fuCHJqn77Np+/NCaJz6B237shZlGk7wA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dlPppG5jvnLPLLa/pDk5OT71eBRFa49H+roN1KDGQFgYXAJLkfJoHSCDb7fKAjEw3PjDKrdTTIke6XGAm7NezQJV2escJRWkth3rv4tIWfxnwJ7GfWkU4j7wGEb9NQoZDDCvyTu29FwYhYQ0trpwQ28lvDIaoTI1Sqr31c0C0yQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W8MvQ1lB; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W8MvQ1lB" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so11749166b.2; Wed, 19 Jun 2024 12:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718826182; x=1719430982; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=n9z63p6lskMirNgu/7X6osNx5PNpqMrbPB+Wm9ztJrU=; b=W8MvQ1lBWfT/IjO68EMrphvJqOjgvG621IQxIsh3Gs2ZqjlNiqVz7HL0YNgqRuhI62 xyamyR5RXBw7KE/LSrahlYd4AImhhAvFu1hgLWx86cwKy2qpj9xtyb4kjSbDUB3o+2bP M8qcV0w1bHpCycf4v8AoIgw2T3yN6Ou1ukfBC496mVOmRXjte1G7u2KjPGDQwpIbh1U/ yLCwXXutKjTixUmCp2DVx1BcTmLfOA5Z7S1XeLbvER+ZjiPNACpktB82R31Sp/0Ulmo4 BvvgURBNsfrtDAO3Xpjnbgu6qcwr83dDPsuNrCyopX+q9wtFY43opmAnUHR3mkT/DtpC HHsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718826182; x=1719430982; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n9z63p6lskMirNgu/7X6osNx5PNpqMrbPB+Wm9ztJrU=; b=UCZEweRik2r4ajjfY+m2M6jLPkrom1csmW26bbAcZu8pp9lJ2W0YL7AZLjhsM7MX06 Qi1Q0SF3/99GRburOjjnxOFN1tZv0mmEJ0FhVMWI2HlP/8FXIPa9PGzRtJEAtzD6ova/ SIGOKtilkaXrf28UTJJSMOy2ByuYorOWjYHneIKh6lJ7e0+VGprWJqCdqNfXroA2Icqt smjm1vfY4Z7My1M9FD73RiQ2Y4gcmreacrGwCsAIDkQ2FuSXRSc5oCa61p5gGVlCrAA6 lELAZcs855PvIaN0wdIwy8y4rzIKkP5nCt2vWQbbMoWxbhP7MIhk3t3HPo49/0Kp2Owy ajng== X-Forwarded-Encrypted: i=1; AJvYcCUwyyrQA+WdQ4pn1zlP580D8coUgiuyEPlngjtoIXFZsADmgZPqsZRd+wXX6q8Gw2qsnA1I/V/xHqSF1ML2BQ+XKKnBpKoKRrnieyHIMf3dHAnrfHiSta09/Hna8uGyypw+L9YsM7Q/1SqxjRFA X-Gm-Message-State: AOJu0YwxlZUP1nNLnYxOV6fiCplaRYP1RjhqwYft65wPgnVk/y7HWrch +q2OWf0qpJxEOkK6raCIMYXyCzwWeY6np58Qr3Qzc7NdPSbidivryMM1jPcW X-Google-Smtp-Source: AGHT+IGhnnBv0QoNxw0IXvKXUeKA7OoxHA1cnv3LEAsfVt/4l2CCSjKit1x7O4p8BBi5/H5VF3Bmzg== X-Received: by 2002:a17:907:a095:b0:a6f:b34c:76eb with SMTP id a640c23a62f3a-a6fb34c7838mr180373066b.54.1718826181747; Wed, 19 Jun 2024 12:43:01 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-103.cable.dynamic.surfer.at. [84.115.213.103]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56da3385sm688365766b.24.2024.06.19.12.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 12:43:01 -0700 (PDT) From: Javier Carrasco Date: Wed, 19 Jun 2024 21:42:45 +0200 Subject: [PATCH v2 2/2] USB: serial: garmin_gps: use struct_size to allocate pkt Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240619-garmin_gps_counted_by-v2-2-f82f10ebbf28@gmail.com> References: <20240619-garmin_gps_counted_by-v2-0-f82f10ebbf28@gmail.com> In-Reply-To: <20240619-garmin_gps_counted_by-v2-0-f82f10ebbf28@gmail.com> To: Johan Hovold , Greg Kroah-Hartman , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1718826176; l=869; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=qCJk9bWEc+/fuCHJqn77Np+/NCaJz6B237shZlGk7wA=; b=cexK0HonegmOr1iAcrxTSFtX32J5Razx8ZpgrRL6ih52oWsn3hR9bgc/J3g0tkdX6cLrnZG8q eEZ8mKg7vbcBWjSIG2VzRHf37QEneJDUhAV9LGoM2IcgC4OZhrLYD1o X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Use the struct_size macro to calculate the size of the pkt, which includes a trailing flexible array. Suggested-by: Nathan Chancellor Signed-off-by: Javier Carrasco Reviewed-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/usb/serial/garmin_gps.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 57df6ad183ff..6d6ec7eed87c 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -267,8 +267,7 @@ static int pkt_add(struct garmin_data *garmin_data_p, /* process only packets containing data ... */ if (data_length) { - pkt = kmalloc(sizeof(struct garmin_packet)+data_length, - GFP_ATOMIC); + pkt = kmalloc(struct_size(pkt, data, data_length), GFP_ATOMIC); if (!pkt) return 0;