Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp584369imm; Fri, 14 Sep 2018 03:15:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYbkouNrKT7JnmQh6zFWe4curabDMFZ1kbOaZ90Yd36R1eXXXQzSGOwELi6q0nGw8pl2yJ9 X-Received: by 2002:a17:902:7c96:: with SMTP id y22-v6mr11594972pll.332.1536920109999; Fri, 14 Sep 2018 03:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536920109; cv=none; d=google.com; s=arc-20160816; b=ZjNSM3z+aeOOJWMwnFYiMdPs6n9eWa7xmSuCq7baMFG8WYmJSFmpROUoIcT5zkDdGH GxGcc3w7u/v4KYGKlZUZeC3ZQoqq2TpNQJO/LSPICqJD8rFgwObZ20Iksubj45id8Ziu wccRHCo/Hy5jsrWaD+WCsYal7B2NXHsFxWFTErZhyLxUXyWx6woQMfdeuXvGgcgsKmap JZ33X8UZe8uI/qO5koX2SPcaQm0g1j1TMviwl/syFfNY7R5NkDvrGxdxyz076M6CzqBv W8IOmB8TgPDXlK1ACYKcLxU5FZiRHOtw75iM99QEnqOV46ORbtWMnKDB4mqkMLVUfhBL r9nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=5LYAsr7R3L+7NM5eB+7I4i5+RFUvwLjoUKcL0LC7swY=; b=sy6LVp+Q9EGax1vrXuMmDq4iP3M88kIQDESVyM+S9PN5GQE8W+0NR+xvdnjtnM+b92 z08yF7cd6M17UtVMosEKxYd78WG8vcc7JOaEjzheep7g5mmh1uWvc1tS/n8dezsQEaaJ r7wTv1O27S8bhHbANy8onROMCpTpQ3N9GCraKu7hLUEDiv+UlA5ogxBjE2SWEYobUvbE 9gNAFPIw+UsT6xfPMJF0dgsWWKC7v8ovTgw4UBqH2YHRbi7r3MVr+NBvDKqcSOUNxwpi vJzLCuZ/Pv4d7WCU3BAT6aMP1K0JwiGa3LKgH2Gwhd0y7AQh4Ta5VH2dTJiBQ8HX0cxg THvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="mvu4/+q+"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5-v6si6036772pgc.607.2018.09.14.03.14.54; Fri, 14 Sep 2018 03:15:09 -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=@163.com header.s=s110527 header.b="mvu4/+q+"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728024AbeINP1H (ORCPT + 99 others); Fri, 14 Sep 2018 11:27:07 -0400 Received: from m12-12.163.com ([220.181.12.12]:45775 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726868AbeINP1G (ORCPT ); Fri, 14 Sep 2018 11:27:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=5LYAsr7R3L+7NM5eB+ 7I4i5+RFUvwLjoUKcL0LC7swY=; b=mvu4/+q+uJZ1ShrYTnq+46wuX/MxREmIRx XsUbE+DeqjSsufeBTP+q91rra88iD8VACL30Ztls/dmkki/Dtnod1fU8+bObJLO9 tob8O/qstiTuSP8j9onxxpT4KR/nadaHKUp11vr0dJdSjNHUTIn6M7Ep1YuLVH3+ Y6iYliD94= Received: from localhost.localdomain (unknown [117.136.0.171]) by smtp8 (Coremail) with SMTP id DMCowABnzqa4iZtbcIyaQg--.20838S4; Fri, 14 Sep 2018 18:13:13 +0800 (CST) From: Dongbo Cao To: colyli@suse.de Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Dongbo Cao Subject: [PATCH 2/2] add some safety checks for label store interface of flash dev in sysfs Date: Fri, 14 Sep 2018 18:12:59 +0800 Message-Id: <20180914101259.4169-1-cdbdyx@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: DMCowABnzqa4iZtbcIyaQg--.20838S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrur43JrW7GFyfuF18Xr1fJFb_yoW3WFg_Cr WUWr4kGwsYkr17Z34xAF4IqFyYgrWqvryFgF4jvr1SvF43AryfW3yvvr93Jws5WFySkay7 JryDG34YkwnakjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8tPE7UUUUU== X-Originating-IP: [117.136.0.171] X-CM-SenderInfo: xfgev5r06rljoofrz/1tbiGRnB3FXlf+4kvQAAsl Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 == &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] = '\0'; + if (size && u->label[size - 1] == '\n') + u->label[size - 1] = '\0'; + if(d->c) + bch_uuid_write(d->c); } if (attr == &sysfs_unregister) { -- 2.17.1