Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1428405imm; Fri, 14 Sep 2018 18:22:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaFNPf2mOrhLYTMx2rIZ5m6uUadfbJGIjwoMlCwG2T0zKzMdGtGgnaSeY6BgKWCNSjsxt/b X-Received: by 2002:a62:c60e:: with SMTP id m14-v6mr15090432pfg.40.1536974568214; Fri, 14 Sep 2018 18:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536974568; cv=none; d=google.com; s=arc-20160816; b=cpZcbmdaGEkgXJwJ32B2n2l0/JU8mMelo7hzPW6yrZRNcfgbd67t6LXuYbDqCxmMLU KoEL0awl0oaiXjycSKZqdPbF4tiuLFwmUBa3MHl9+/rlseWrFJwofpIrftG8yrEYcKcZ ZTs+yNZAMw9Xfi9ZBWyGeBObz7qcwO/NqY8LAXEQu9yZGn5JG6o8v5G5DIq3FQHTdU4i wBt7BOAquroaeReQlJ8Mvhpy28i9hI9sOx7XYfmSRGaL3wXD68v19xCLcBtaelHyxx2C p0etDZrSNZIpECUXehEHbVdoSiLhG3BQ4vRiDglxDhvT8QqDaHMpgd5cM0rFbwbYDtCv P3Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=bQFUf4CE1xts/aF6MMKroo2UrvrAeve9ybZOKVzV0c4=; b=zaV6Pmqi0C5bs64dI2h5KpqJus52C0xfGfqVebRlwbOaTQOX4NImbFNRwZkYfHC4TA yJeFVo6AfbqmAdIcJBLwWRCmXvVoSCFsqv4gKtf2vWZJvgCOzI0og5wk0xUytNjqCdis w5d7+opZbBhQ4gMuPrVjL3GSvUNkc9PxcqxRhvg3fPv0Vj5TqHvvb/p/904pMMA7hbHV XAYJFegra4R+vqbEbR/QTOBf0djp+9gbm/sY6VNoAru6opnXKGV9GZPp7UWJTpMLGpad ywo+Qx0UgaIPgyyHrR1tMLpgNiEJ028Gvtg86XuDNv3UoXmulaw+uCfYpwmkcIbANzk+ 8dqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D+yi01bd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si8234022pgk.491.2018.09.14.18.22.33; Fri, 14 Sep 2018 18:22:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D+yi01bd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726995AbeIOGhv (ORCPT + 99 others); Sat, 15 Sep 2018 02:37:51 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35134 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725746AbeIOGhv (ORCPT ); Sat, 15 Sep 2018 02:37:51 -0400 Received: by mail-qt0-f193.google.com with SMTP id j7-v6so10494663qtp.2; Fri, 14 Sep 2018 18:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bQFUf4CE1xts/aF6MMKroo2UrvrAeve9ybZOKVzV0c4=; b=D+yi01bdTKNQSI2BRI++aWKm3gQu7VrODhQem5ePO2aK8+ZBa38HGLTbJbL02sIcPS rRBhXN3Z6/bGJTIcEyh3YRUZ5wimBNg9Uwe2Gm2yHw2p7SnpvuUGpaRAqbYdrM80OJGI PHo48JHslugIe01BwWqE3SYPsWooXqCztiCAk7LsVJnXn/z3rlRuEYhhO4nsGnL+ASyL bFbjlMeQahZbOAG8UUS+ifs4K8yviX7ahUVq9NVvsnuukB1Qo4pnrG8vkkaMrB42RGst nXvKGdU/4aEoau72onIYLTJvZhlIA9sqBeyP8m+4Tf6lfQVRwyeKB7oHwLKn0VDkiM0Y Ihyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=bQFUf4CE1xts/aF6MMKroo2UrvrAeve9ybZOKVzV0c4=; b=Kedc1bZzNhzZ8pS6dNqBBJoS6/4iyMa+INNr7F1cmYoaH3tcj+OqFEfKMQIlBWX+89 AHdekSXOeZ3z2J2p7vOOhVK4uX10BGZou0pwuCNtGH2LAVcaD0fyCTxf2pDcU3sfrlbW RGEkReyTJR3dswI2vCUHEvb0oFwFKBQoAV54iaYLeM9J+//bn7Jar076dXtPXxmZ5luR TAe52mlQd56WPB89NZXpz3S4fzDSqA4CTbgR/fabyij15rH7iISHddmAayJ/GbSRpcYE mexuLgiX0G0+42MQRhFJ0mOM/2H8NrYK8P93pxszPMLzZ2X7HB2p/jNfW2LSTM3y2vfq Z8Sg== X-Gm-Message-State: APzg51D/oSwF3jEnCWtrR20pVg4cw91/nPCcVmUrYgIJcq56S6PEdKLU Ru/7Zn3vf0hLTjahKluwxkt3CAj4C4UB5jbreTI= X-Received: by 2002:a0c:ae71:: with SMTP id z46-v6mr10967900qvc.108.1536974455433; Fri, 14 Sep 2018 18:20:55 -0700 (PDT) MIME-Version: 1.0 References: <20180914101259.4169-1-cdbdyx@163.com> In-Reply-To: <20180914101259.4169-1-cdbdyx@163.com> From: Junhui Tang Date: Sat, 15 Sep 2018 09:20:11 +0800 Message-ID: Subject: Re: [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs To: cdbdyx@163.com Cc: colyli@suse.de, Kent Overstreet , linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Seems something wrong when size =3D SB_LABEL_SIZE and u->label[size - 1] !=3D '\n' please check again. --------------------------------------------------------------------------- Tang Junhui Forever me is me --------------------------------------------------------------------------- Dongbo Cao =E4=BA=8E2018=E5=B9=B49=E6=9C=8814=E6=97=A5=E5= =91=A8=E4=BA=94 =E4=B8=8B=E5=8D=886:13=E5=86=99=E9=81=93=EF=BC=9A > > do some checks on the label's length and ending. > > Signed-off-by: Dongbo Cao > --- > drivers/md/bcache/sysfs.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c > index e64c718f..cce793ef 100644 > --- a/drivers/md/bcache/sysfs.c > +++ b/drivers/md/bcache/sysfs.c > @@ -447,8 +447,15 @@ STORE(__bch_flash_dev) > } > > if (attr =3D=3D &sysfs_label) { > + if (size > SB_LABEL_SIZE) > + return -EINVAL; > memcpy(u->label, buf, SB_LABEL_SIZE); > - bch_uuid_write(d->c); > + if (size < SB_LABEL_SIZE) > + u->label[size] =3D '\0'; > + if (size && u->label[size - 1] =3D=3D '\n') > + u->label[size - 1] =3D '\0'; > + if(d->c) > + bch_uuid_write(d->c); > } > > if (attr =3D=3D &sysfs_unregister) { > -- > 2.17.1 > >