Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751177AbdFAOFH (ORCPT ); Thu, 1 Jun 2017 10:05:07 -0400 Received: from mail-by2nam03on0049.outbound.protection.outlook.com ([104.47.42.49]:40289 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751090AbdFAOFE (ORCPT ); Thu, 1 Jun 2017 10:05:04 -0400 Authentication-Results: google.com; dkim=none (message not signed) header.d=none;google.com; dmarc=none action=none header.from=caviumnetworks.com; Date: Thu, 1 Jun 2017 17:04:53 +0300 From: Yury Norov To: Alexander Potapenko Cc: Dmitriy Vyukov , Kostya Serebryany , Eric Dumazet , David Miller , stephen@networkplumber.org, LKML , Networking Subject: Re: [PATCH v3] net: don't call strlen on non-terminated string in dev_set_alias() Message-ID: <20170601140453.fp7iusjomq65tu6i@yury-thinkpad> References: <20170601123829.51794-1-glider@google.com> <20170601134737.7dp2pbnek26b6kqf@yury-thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Originating-IP: [176.59.49.173] X-ClientProxiedBy: AM5PR0101CA0020.eurprd01.prod.exchangelabs.com (10.169.240.30) To CY1PR0701MB1276.namprd07.prod.outlook.com (10.160.149.19) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY1PR0701MB1276: X-MS-Office365-Filtering-Correlation-Id: c690e05a-35f7-4b88-be47-08d4a8f732f6 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:CY1PR0701MB1276; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1276;3:MWNqr9yI7nqNazYSptkhFxqJGeS2dUZyzIDv6yQGo4KXuMaOqY+jrihksYKu74atLmA/wmbJD6h8LoKuu3KvP/P4zwDC3ZeTfAmIllqQ7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F1p5pSZdzac1WSsroG3lBa2EJIu/cqTKbm57HmWNITnP56D/wmwiQqoA+1/lQvXXpn0j5GPQBuSOz2yoVlZVfIIsL3Cb3PVAP4jftEO5E157kF1sP9AEI/1xJrgfGCains+2e1PVEApg6+l+E+8EnE7QTUHKVdJzGyK3I5hjITTP1Kl/aAwZTQDQN2mpruIwp1sWy79XbM6tEeje9k8jfnIz+FxZTXsQUAYyFjuWUt0vKc3kBuYzn97+J0ri3QSh0o6aT66Sl1AI8EfNrPSPGQ5wByBrhtoucZUzOTdA0Bq2hsdLgDoEnNmn/lq7Fgg+ChKU5ESK0Gohf0BIp2Gad8YarM3Tdeq+ofl0GF5OxfOcz4A4vnrYElnGsU0KRm5uzN0vStqRVeqMjtAZUjCaFdCouEV93AF47vQCfIGvaHgNlJiwQuLR3zXaAC9fLgm9sptSYcHNYo+bUWr26OX9XsJ12yUnwH/2UbZ+GJ+jOCaNNPoZSwY59XxmgyRefIhiFO94nuAd4snIqezjdbSTAGiRbmFpwFwnSdgdprw5TLqWkQqXlVNxqdSpSyu7zVvFj/T4+XSU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(211936372134217); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700099)(100105000095)(100000701098)(100105300095)(100000702098)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(100000703098)(100105400095)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123564025)(20161123558100)(20161123560025)(6072148)(100000704098)(100105200095)(100000705098)(100105500095);SRVR:CY1PR0701MB1276;BCL:0;PCL:0;RULEID:(100000800098)(100110000095)(100000801098)(100110300095)(100000802098)(100110100095)(100000803098)(100110400095)(100000804098)(100110200095)(100000805098)(100110500095);SRVR:CY1PR0701MB1276; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1;CY1PR0701MB1276;4:y0UjIoAwiu/5q5B9Zl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S7E+vxwwXeP9oUi6SQQkKeJBm4PThkii1pC8c4y1P9MtvUi5wKZF3?= =?iso-8859-1?Q?UVdmdR/PN7wDz6+BNcKWV8Wke/oRlNFl8xDy7KFJkQnj9OKGfhrms1Kqwi?= =?iso-8859-1?Q?noN1mS9Z/YqYh87VRYhf2abUvcoFD+Orju9dHWeWzDjtrAKccu1lNq4qro?= =?iso-8859-1?Q?r/I/540HcCozVuduJgD+jQ3Ryxoa3ee+G7A5dbQaUI7V5iFOK+FA1Kri8x?= =?iso-8859-1?Q?evElRjGouElG1NjMaWj/4kwYsenhYYHXzxPPnzqx5aY2T/52QgJ4h1r0fg?= =?iso-8859-1?Q?V/zOgzSiSC8xDGrkit7bJC1UohKPNHsvlg=3D=3D?= X-Forefront-PRVS: 0325F6C77B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39850400002)(39450400003)(39400400002)(39840400002)(24454002)(377454003)(189998001)(54906002)(8676002)(4001350100001)(2950100002)(6916009)(42882006)(6666003)(2906002)(33646002)(6496005)(1076002)(6116002)(110136004)(229853002)(3846002)(305945005)(81166006)(23756003)(38730400002)(9686003)(6246003)(33716001)(2870700001)(53936002)(7736002)(42186005)(66066001)(53546009)(47776003)(25786009)(478600001)(76506005)(72206003)(4326008)(83506001)(76176999)(50466002)(50986999)(5660300001)(54356999)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0701MB1276;H:localhost;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1;CY1PR0701MB1276;23:jbNGMfBZW88r5D1J7vYU6Xd/4ph83i/FVkp5U?= =?iso-8859-1?Q?RCo3D9sjEgafac1xG0cLOuiBZxz5QFJTJONfmdweAKuHz9aa6ab3F+jrSk?= =?iso-8859-1?Q?Qq16lIg1UpHeyKIsgaEROBWt09zCbOKaGWrPpNvlfRMBpTELVZ1JZJMnp4?= =?iso-8859-1?Q?FI1cKeoyCBQ26Uof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PQPeU4WyFoJ1GhIU8aiGdAUTZme9cRGsyuaR79NklewGxi5jIOePLVUW4xloRBWDH9kf2ePN1ZWA9HQWo9KmjKTu+FzkBn7Z5yxh37nWoSLOtInsrNoXEoae+AvkbpsdEqKCPGBtv65AK/YS7mKVGNaigR+RKJxGymU9JUX4Wfn7/YJMcwIp/h9aKaa8g0OtPHxrPtBE2WxPFKu8EmTBPELIZnfN/d1hRPNxP4NromLhgpQg7yIfZToinr0FMZFUqXjXkpimHaLzBiTca5HLorALpxwk1ph6sKS0ws1nFJB8t9qXzJKjL4pnwncJEHfKhemY4eG/3/ad2plKMqGvl8KnA7ZGSmoSYaX;24:ah7F/dsnpFEMF/bqGoUyUPoaDeGaeWfFq5ZUtPU0HodHfOh8HEQfZC12tqHxPtruZ1I50mdtwdd+Wi7HlW3VwcVosBkFH7FF0dd7rRans/Q= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR0701MB1276;7:EIF4Nl88MOX3GnYledswrt0ds8bX3X+edzBjnf8/LnNSYOTkAXCVHjrl3jmwAsePhCTv/UlKYSMHxtXWIeAcMVkVpQjCM8bagkkaJV7l6kjhHp9vCKpKO0wwKPYdW+BQK4NBPBFDir1biql0j4noJrCYP1oIJPZwd/4OG9boHqcSuKmmvADuFVMtmxwOw4ukIzyByxJ96UjQievZ6cQ8H2o65YyjhKB5B3fGxFBR7gkLuj0ZUd8jl2YDiZCAiHAoGfrWEFTQ3wgC3Lvpp5/c0iKIELZDAZbc0Nj3NGyuRpPjCxNMDkUotvBhohqR1gNCxnCfR5WX4II2gzseZHuJoQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 14:05:02.5408 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1276 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2268 Lines: 67 On Thu, Jun 01, 2017 at 03:50:33PM +0200, Alexander Potapenko wrote: > On Thu, Jun 1, 2017 at 3:47 PM, Yury Norov wrote: > > On Thu, Jun 01, 2017 at 02:38:29PM +0200, Alexander Potapenko wrote: > >> KMSAN reported a use of uninitialized memory in dev_set_alias(), > >> which was caused by calling strlcpy() (which in turn called strlen()) > >> on the user-supplied non-terminated string. > >> > >> Signed-off-by: Alexander Potapenko > >> --- > >> v3: removed the multi-line comment > >> v2: fixed an off-by-one error spotted by Dmitry Vyukov > > > > [...] > > > >> --- > >> net/core/dev.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >> > >> diff --git a/net/core/dev.c b/net/core/dev.c > >> index fca407b4a6ea..3e3b29133cc9 100644 > >> --- a/net/core/dev.c > >> +++ b/net/core/dev.c > >> @@ -1254,7 +1254,9 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len) > >> return -ENOMEM; > >> dev->ifalias = new_ifalias; > >> > >> - strlcpy(dev->ifalias, alias, len+1); > >> + /* alias comes from the userspace and may not be zero-terminated. */ > > > > So if the comment is correct, you'd use copy_from_user() instead. > Well, the contents of |alias| have been previously copied from the > userspace, but this is a pointer to a kernel buffer, as the function > prototype tells. > Do you think a confusion is possible here? Yes, I think so... If pointer comes from userspace, it normally points to userspace data. If you have the data already copied, just say: + /* alias may not be zero-terminated. */ Or say nothing, because at the first glance, using the strlcpy() instead of simple memcpy() looks weird in this case - you know the length of the string from the beginning, and should not recalculate it again. Yury > >> + memcpy(dev->ifalias, alias, len); > >> + dev->ifalias[len] = 0; > >> return len; > >> } > >> > >> -- > >> 2.13.0.219.gdb65acc882-goog > > > > -- > Alexander Potapenko > Software Engineer > > Google Germany GmbH > Erika-Mann-Stra?e, 33 > 80636 M?nchen > > Gesch?ftsf?hrer: Matthew Scott Sucherman, Paul Terence Manicle > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg