Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp159666iog; Tue, 28 Jun 2022 19:05:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1suLwPqlG7/3EBIK2LLhOVkA4fAsi67sK/qf/Y2QapeFe/vyKOdAon+heNgV1chsRuMP8Ey X-Received: by 2002:a17:907:94ce:b0:726:449e:73cc with SMTP id dn14-20020a17090794ce00b00726449e73ccmr1024699ejc.270.1656468344498; Tue, 28 Jun 2022 19:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656468344; cv=none; d=google.com; s=arc-20160816; b=yi4vUcaI8FXcaAa2vTd/XFiEfbsWLUIITIqwqr9LC40yaoBJJqp6iXswqB78ePRp0q IpeZINxugPRRjs1fyDoFhygVIhSCa6cJ0mYonJsMQt3l+qtqnPL3CzM1shFzjyr6PMU9 7dLbMFKkIUQLieXFDccdMZnDcDeG4xxsGwFJ9ImHtAW+8REMoyo6Oqtou+DvJ0K1tEf3 rtb972uRHrWJjwvPNbmTFytbf8RdKKhySI//y3tLK7zPiOWR4z976doN3pYYZWe7rmmn 6ak5vfbYyCXZERvyZD2JS/cYvxXT+tJjJ2xQGP+Pwjungeie0fSiIYkvnTStwKl8D8Wi uPTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KIhlFiRLTeYDajDFixtlLrmUsyayl0HijGJY+Ov1teI=; b=J3HhTIWA1eUKdnQsOhV28+V5ju7DTYs3Hmkz6XfuJQ4dPMpvAiQ18UoUwjiUjYe9lh FdEIRfalX1NSedy1iOEkCHK7aJo+Cc0cZj59DSjcXpaPDGrCXd2tdvNlkvWiVKCyaS+Z hYz04f3BiMKM1lULqN5+zhIZlFCC0XalhYiwOD91yBA9gWBDoXUicJwxj3tsAtGqb/33 0q7CGONpi8DMiWuDvb+Zo41GXy8W/xPjJ5ZVcTkkZNgjmVCAn7FJJ27UFlWrA0hVr1oN zLkMKMHo028WFt+IzjuqYQ6N9hcITD6JCBMTlPDITI1kBEKfwMpjKarqqDAnsdWqNYeg hUfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dInfvLhF; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a1709065d0700b006e88579e94fsi1183447ejt.798.2022.06.28.19.05.19; Tue, 28 Jun 2022 19:05:44 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dInfvLhF; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbiF2Be2 (ORCPT + 99 others); Tue, 28 Jun 2022 21:34:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiF2Be1 (ORCPT ); Tue, 28 Jun 2022 21:34:27 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2BAA25C7C for ; Tue, 28 Jun 2022 18:34:25 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id mf9so29574906ejb.0 for ; Tue, 28 Jun 2022 18:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KIhlFiRLTeYDajDFixtlLrmUsyayl0HijGJY+Ov1teI=; b=dInfvLhFqD80OSMjcdIXIwxqsZ0OxIRfxIxJKDP2RCtkO7IOfrBejrA454rQqdWxfY a5PadiFHJ0qqvhgz17zXlaifLpILDBBcd8CmfH/4Ojlk43kDd5Dq5UuuA89M0z15gr/J 9OzmnYu3wXd2UPA5kSTBY39kbRTiQuNM6M6tCupdwF6UdlgW0yjDULz6Adw7W+8HkalI 7pSCWE1WT9OziivUMvmxGOdlEPb5e/XDsK4vtHdCaSeDld7wigZ+t4gS1dVekCQqzMBr ey/UfGiNrARgRHfjXH0GLMfYrQzrbEGam+RwSkkXUZ0lUR1J4mroXf/AQW5QJa7QDEuo C1+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KIhlFiRLTeYDajDFixtlLrmUsyayl0HijGJY+Ov1teI=; b=5NliE23mONa9fXyj15Ql1TXJ7cABGMPqfaJfANlp+vJsu8O5r9eOD6FOn0/cUTUJ1z v283mMzGh2j6tGeqkHIkLyKbLR0A52VThnOYaWEDDIUhq9C8OGX2sShX/WB16hF+aGHN PcyN/cAq4ieQzBMsespywnCDhKVxTw7YlBouGf5kKoekBKcyM5b3DsEGfhTh12wTyM12 3kRi+SKt0PdJlfy0V9BrVihbHx+f4XzDg0POFbJvK5eFY1M4X6l94Fgnx4hE9RXLDJsu DbX6s1BmE2NSIbEdIHR4NEDb+sXf83W96JjtnSxs9XKNIPDtwo1moboiL1qHUZgjFxL8 qHTw== X-Gm-Message-State: AJIora9sRhjJr5+iDA6gkMTUoW6K0Qc7mxh5Tp5dbD2cT14vK0Juhk5x 5wpIYYK1oR28QtwKjKwCaz0esI5YUbnIvI0CAFo= X-Received: by 2002:a17:907:6ea8:b0:726:a8bb:5a3e with SMTP id sh40-20020a1709076ea800b00726a8bb5a3emr883622ejc.753.1656466464303; Tue, 28 Jun 2022 18:34:24 -0700 (PDT) MIME-Version: 1.0 References: <20220628055949.566089-1-dzm91@hust.edu.cn> In-Reply-To: From: Dongliang Mu Date: Wed, 29 Jun 2022 09:33:43 +0800 Message-ID: Subject: Re: [PATCH] gfs2: fix overread in the strlcpy of init_names To: Andreas Gruenbacher Cc: Dongliang Mu , Bob Peterson , Steven Whitehouse , Jean Delvare , syzkaller , cluster-devel , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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, Jun 28, 2022 at 8:06 PM Andreas Gruenbacher wrote: > > Dongliang Mu, > > On Tue, Jun 28, 2022 at 8:10 AM Dongliang Mu wrote: > > From: Dongliang Mu > > > > In init_names, strlcpy will overread the src string as the src string is > > less than GFS2_FSNAME_LEN(256). > > > > Fix this by modifying strlcpy back to snprintf, reverting > > the commit 00377d8e3842. > > ... if the source string isn't NULL-terminated. But in that case, the > code will still do the same thing with this patch. In other words, > this doesn't fix anything. So let's check for NULL termination > instead. Partially yes. Even if the source string is NULL-terminated, strlcpy will invoke memcpy to overread the adjacent memory of source string as the specified length is longer than source string. > > Thanks, > Andreas > > > Fixes: 00377d8e3842 ("[GFS2] Prefer strlcpy() over snprintf()") > > Reported-by: syzkaller > > Signed-off-by: Dongliang Mu > > --- > > fs/gfs2/ops_fstype.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c > > index c9b423c874a3..ee29b50d39b9 100644 > > --- a/fs/gfs2/ops_fstype.c > > +++ b/fs/gfs2/ops_fstype.c > > @@ -383,8 +383,8 @@ static int init_names(struct gfs2_sbd *sdp, int silent) > > if (!table[0]) > > table = sdp->sd_vfs->s_id; > > > > - strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN); > > - strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN); > > + snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto); > > + snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); > > > > table = sdp->sd_table_name; > > while ((table = strchr(table, '/'))) > > -- > > 2.35.1 > > >