Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2052rwe; Wed, 24 Aug 2022 15:33:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR6WB9YhmID+kskI9reJ1OLqYXrl1G8b0rJ83sz/1k2QqnvWTWKWSh9FoKpsis6DM99x87RF X-Received: by 2002:a05:6402:354d:b0:447:14c8:e3d0 with SMTP id f13-20020a056402354d00b0044714c8e3d0mr874258edd.43.1661380413951; Wed, 24 Aug 2022 15:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661380413; cv=none; d=google.com; s=arc-20160816; b=APdyrxwCbivxSmdjJCTD/1/yYn8pRHB1H8Zo3j8zCkegRGQT3wBVhT1spCBTmj8ty/ RnBN6K+nquRhK3WqIe0lO3zyW9xKqyTX7vhxrUCUVev7uBw7efhfuw8kszHQl7rqqs9+ DIM9Zbyniv1K8Q87YfTK+lioBwjcjTKcYHSmkstffO7wOo/KjT5h/TaLipinHWwhXu14 HxjaV53xZAQ8DAzZ2qoGcC7BDxE0TvUHtWh+vnxgxp5gqzhoYmX50NHfeHLtBvy4QCgf KSYDlB9edQd58Di23HYz4FQnk6FpCrbO0dYpOqz1wk2erW2vOQFo0c7WUCvz1SDySRW/ XS+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=QOW3wnu2ZnyuEoOT8DPkohU9H64WQLsDiJ6QzYo9Q+w=; b=IFkix6OTGrss/WKPz7PO4t0RG63W3xkVmHO840gQVKxVwYP/U+psUzjsLrj56shjjy QXjQfIPj9jmpVcwrfqDpcH/dSMSZB7IISYZdkZyHT6BiXjXmGxdRp+mr8Dgx8IvMbG2K LVAQzADj7ID5nOUd6j2c40l/alJ7vlXiItt8ZRi99Ks2o+qL3FqXNkE2gGrexynrIVGO GccvRQZxcHaTQW3uNsXlZYx0Ezw+ox9OrAVHqPLoz5fvM+/6mq/P83jRqXh6L7aiiAFj w5HawcOacKcgTGwZ7qpZNfU272z+a7L7/O+f0WWmz8emCZ2dbKJJRjoQbH9wwbNy5wBO g7CA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t17-20020a056402525100b0043e1ec7a427si5777724edd.570.2022.08.24.15.33.08; Wed, 24 Aug 2022 15:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240641AbiHXWCh (ORCPT + 99 others); Wed, 24 Aug 2022 18:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231190AbiHXWCf (ORCPT ); Wed, 24 Aug 2022 18:02:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F61875CC3; Wed, 24 Aug 2022 15:02:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC6E561920; Wed, 24 Aug 2022 22:02:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F56CC433C1; Wed, 24 Aug 2022 22:02:32 +0000 (UTC) Date: Wed, 24 Aug 2022 23:02:36 +0100 From: Catalin Marinas To: Linus Torvalds Cc: Steve French , CIFS , LKML , linux-arch Subject: Re: strlcpy() notes (was Re: [GIT PULL] smb3 client fixes) Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 23, 2022 at 10:37:38AM -0700, Linus Torvalds wrote: > On Tue, Aug 23, 2022 at 1:56 AM Catalin Marinas wrote: > > With load_unaligned_zeropad(), the arm64 implementation disables tag > > checking temporarily. We could do the same with read_word_at_a_time() > > (there is a kasan_check_read() in this function but it wrongly uses a > > size of 1). > > The "size of 1" is not wrong, it's intentional, exactly because people > do things like > > strscpy(dst, "string", sizeof(dst)); > > which is a bit unfortunate, but very understandable and intended to > work. So that thing may over-read the string by up to a word. And > KASAN ends up being unhappy. Good point. We could attempt a single-byte checked read on arm64 as well and then disable tag checking (the arm64 load_unaligned_zeropad() doesn't bother with this). For KASAN, if we want to be more precise, we could move the kasan_check_read() (or add a new one) in the strscpy() implementation that actually takes into account how much was copied (non-zero bytes). Not sure it's worth it though. The check would be post-read though. -- Catalin