From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 376D3C433E1 for ; Tue, 18 Aug 2020 21:35:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 033A2206DA for ; Tue, 18 Aug 2020 21:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbgHRVfA (ORCPT ); Tue, 18 Aug 2020 17:35:00 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:44812 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726372AbgHRVe4 (ORCPT ); Tue, 18 Aug 2020 17:34:56 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 748AC1C0BB8; Tue, 18 Aug 2020 23:34:54 +0200 (CEST) Date: Tue, 18 Aug 2020 23:34:53 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Dan Carpenter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: Re: [PATCH 4.19 073/168] media: firewire: Using uninitialized values in node_probe() Message-ID: <20200818213453.GB25182@amd> References: <20200817143733.692105228@linuxfoundation.org> <20200817143737.355562192@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pvezYHf7grwyp3Bc" Content-Disposition: inline In-Reply-To: <20200817143737.355562192@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --pvezYHf7grwyp3Bc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Dan Carpenter >=20 > [ Upstream commit 2505a210fc126599013aec2be741df20aaacc490 ] >=20 > If fw_csr_string() returns -ENOENT, then "name" is uninitialized. So > then the "strlen(model_names[i]) <=3D name_len" is true because strlen() > is unsigned and -ENOENT is type promoted to a very high positive value. > Then the "strncmp(name, model_names[i], name_len)" uses uninitialized > data because "name" is uninitialized. This causes memory leak, AFAICT. Signed-off-by: Pavel Machek (CIP) Best regards, Pavel diff --git a/drivers/media/firewire/firedtv-fw.c b/drivers/media/firewire/f= iredtv-fw.c index eaf94b817dbc..2ac9d24d3f0c 100644 --- a/drivers/media/firewire/firedtv-fw.c +++ b/drivers/media/firewire/firedtv-fw.c @@ -271,8 +271,10 @@ static int node_probe(struct fw_unit *unit, const stru= ct ieee1394_device_id *id) =20 name_len =3D fw_csr_string(unit->directory, CSR_MODEL, name, sizeof(name)); - if (name_len < 0) - return name_len; + if (name_len < 0) { + err =3D name_len; + goto fail_free; + } for (i =3D ARRAY_SIZE(model_names); --i; ) if (strlen(model_names[i]) <=3D name_len && strncmp(name, model_names[i], name_len) =3D=3D 0) --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --pvezYHf7grwyp3Bc Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl88SX0ACgkQMOfwapXb+vI6YQCglanJAWy5M2+yqIDcVnaJjLnA cCcAnR5rfyY8Pk/j/uo1uVKXyK0zUtkw =XDJf -----END PGP SIGNATURE----- --pvezYHf7grwyp3Bc--