From patchwork Thu Apr 27 08:56:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 88152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp129664vqo; Thu, 27 Apr 2023 02:01:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7OYc89zorhWtQnsqWdew/bUGX1BEiCWbKzBM0WPh1oKgxNYKu0cFRpHPy3ABGw8Y29JCDy X-Received: by 2002:a05:6a00:148e:b0:640:dbe5:e2ee with SMTP id v14-20020a056a00148e00b00640dbe5e2eemr1579428pfu.10.1682586098917; Thu, 27 Apr 2023 02:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682586098; cv=none; d=google.com; s=arc-20160816; b=L79VFwkhbSjEMT4aVKht0iEx2Oo9oP0s+Dql33fmyGehu97qwaNaNhoPJXCCcjOLhC GkZzLD1tDLfntI+tzkzIATBPDmgSyLnknqhla8oyf5cV4qD86dDpCKXy17/UwZXbwmnl 3X1bJYsnV/ogsBEqtQvwmTm4PzaYbZmDtyRqskznCifgUNI+J/vFHy01KO8kED3MYUXs tT9/t5lhh/j0XhlpVJs4AxVoVf0r2nXZmMEFTvxigSNAxoW1CBBCc4uT9U4Pgx/Iiea5 ZADsYDjMEoFNAOr2/DkWQbNnMTZv3J0wVX6h0Zj5XssYrqxU8BtdjRxEF4B8GzzS37UT nx9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LL1aKNxPh1D2em9KcZly4hssoml0HrPB5ANjfqGzigY=; b=zwvqdA4idUd/K/zgt1SzLjRJo4n2eH1AEUhxDuBLKEGczkmNyuRiiBpRL61TBrcVJ1 GjGeQLUsprZoQMGu4N1ENaPl8snABDjL8wwas3pci9mPp+XrZrb/mhwZp2rx4TeSYIvB ejuhbNEily3scPkyYB/bfXphqNoF7vi86SO9X3G1bjNO+wieN7SlBW1i8EhAtCxAwcV6 bThOHuGFGpZL6hjMlA78SZ/LKaOfx5Cy0J6kwfLIZkzim4uWqLNZFtkRxpEovPnkwILX zyzdzoMNs7BzXHFI0rjKnKsVWsvLOxbLhXbKc0mi5w8qDub0GqGEdbgXZnR4+JYsQgvg 6s9g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020aa79435000000b0063d334a2eb2si15285516pfo.183.2023.04.27.02.01.22; Thu, 27 Apr 2023 02:01:38 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242986AbjD0I5Q (ORCPT + 99 others); Thu, 27 Apr 2023 04:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbjD0I5O (ORCPT ); Thu, 27 Apr 2023 04:57:14 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 637EC19AF; Thu, 27 Apr 2023 01:57:12 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Q6V3n03fMz4f3mJP; Thu, 27 Apr 2023 16:57:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBH_rHjOEpkmCsBIQ--.37560S5; Thu, 27 Apr 2023 16:57:10 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 1/3] md/raid10: fix slab-out-of-bounds in md_bitmap_get_counter Date: Thu, 27 Apr 2023 16:56:10 +0800 Message-Id: <20230427085612.1346752-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230427085612.1346752-1-linan666@huaweicloud.com> References: <20230427085612.1346752-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBH_rHjOEpkmCsBIQ--.37560S5 X-Coremail-Antispam: 1UD129KBjvdXoWrur48urW5XF4UKw4rZFy7Jrb_yoWftrX_C3 4rXFyxJrWUCry3AwnrXw4xZrWjyw1Du3Z7WFsaqrySvF18u343WrW0yrnxt3WrGrW09ry5 Jryj9ayrur4YkjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbkxYFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r18M2 8IrcIa0xkI8VCY1x0267AKxVWUCVW8JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64 xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j 6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2Kfnx nUUI43ZEXa7IU858n5UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764319401236729984?= X-GMAIL-MSGID: =?utf-8?q?1764319401236729984?= From: Li Nan If we write a large number to md/bitmap_set_bits, md_bitmap_checkpage() will return -EINVAL because "page >= bitmap->pages", but the return value was not checked immediately in md_bitmap_get_counter() in order to set *blocks value and slab-out-of-bounds occurs. Return directly if err is -EINVAL. Fixes: ef4256733506 ("md/bitmap: optimise scanning of empty bitmaps.") Signed-off-by: Li Nan Reviewed-by: Yu Kuai --- drivers/md/md-bitmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 920bb68156d2..0b41ef422da7 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -1388,6 +1388,8 @@ __acquires(bitmap->lock) int err; err = md_bitmap_checkpage(bitmap, page, create, 0); + if (err == -EINVAL) + return NULL; if (bitmap->bp[page].hijacked || bitmap->bp[page].map == NULL) From patchwork Thu Apr 27 08:56:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 88162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp134993vqo; Thu, 27 Apr 2023 02:12:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hvrI0ghcVmNY4smljkBofDWIlS6fX0kKowDp1AozqyrBSqrpN5TyEPjZfmw4x3ebfU9Ha X-Received: by 2002:a17:902:c9cc:b0:1a6:5332:25b with SMTP id q12-20020a170902c9cc00b001a65332025bmr698162pld.42.1682586741921; Thu, 27 Apr 2023 02:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682586741; cv=none; d=google.com; s=arc-20160816; b=Cdr3sOKuGRnaMeq9O7rmIoLYnl03EpeVD4x4nQl2Z4m/IfjXbbbqibRuWYIO8mBFqf gbBb3ixhLkNnZaA6oFWwVnJ20uU1dUxXjKXl9JHpmvms2QgkU+XTYPpKsopuU6/11e9Q F8M90u1+K+WGaLVsQz5oGZ0pr2ZNlMxS/IobWibpVZw+ugY6TlAVWoLpaN/7ZagElPP1 ksR+7ZNBN3wGZB74EExvJ2FBGrahNP0DgdpDvb16OPVDSuCd8BlBu0Gfa2H5gypHVo3w SgYPe5oXDdG9sE632WNZzsxG51N6q2Woq9A+wjjFnBE/aR2tznGHJsDVx0bzVLN00TC8 m5vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ot+UPYiBsdEnfyM/KaoJOq4U/OxYbZEJmjdLkSYm2Vs=; b=aDKNN4kFtqD6pnx0E4iV6rcwJALTjfRTCLDxxGlgXqW9upIbgW1cvObAg+Gufh4onP tU7nTb954ru88O17PIgW+SKy89CIe1tH3tjxge1P/vWreM9tqEbTiY7G7Wl6phVR2vtl YTy04S6AMVXR1Fr38MQMaZFk3FLIehQ2tKnQF2rybbwzf9kFZVz6MmGODdR8HQ7Kttll JWJh4rsMnHFUeVaiFWBOnz0kqo7nvt0xbYWi/2vrY9i14L+DyndiFZdLLLZ1Rt9I01mE jIC0qk1Osp85xFh4M+opXymV+XbDV21Ux5eVlE37uX9lV4Ulqxo/HpDE60RVxdpGSrIa vzkg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020a170903229000b001a95babe3c0si14596020plh.371.2023.04.27.02.12.07; Thu, 27 Apr 2023 02:12:21 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243082AbjD0I5V (ORCPT + 99 others); Thu, 27 Apr 2023 04:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242755AbjD0I5P (ORCPT ); Thu, 27 Apr 2023 04:57:15 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64BF3422A; Thu, 27 Apr 2023 01:57:13 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Q6V3m6RGxz4f3kj8; Thu, 27 Apr 2023 16:57:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBH_rHjOEpkmCsBIQ--.37560S6; Thu, 27 Apr 2023 16:57:10 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 2/3] md/raid10: fix overflow in safe_delay_store Date: Thu, 27 Apr 2023 16:56:11 +0800 Message-Id: <20230427085612.1346752-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230427085612.1346752-1-linan666@huaweicloud.com> References: <20230427085612.1346752-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBH_rHjOEpkmCsBIQ--.37560S6 X-Coremail-Antispam: 1UD129KBjvJXoWxCF1UKw43Zr13ZF47Jw4xWFg_yoW5Xry5pa n3J34Yyw4UtryfKF4IvF4DWFW5Was2qrWDt3y2k393JF4DXFs0qw1rXayF9Fy5C3yYvFy3 Jry5JFyUuFyjyaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVj vjDU0xZFpf9x07jYHqcUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764320075721663082?= X-GMAIL-MSGID: =?utf-8?q?1764320075721663082?= From: Li Nan There is no input check when echo md/safe_mode_delay, and overflow will occur. There is risk of overflow in strict_strtoul_scaled(), too. Fixed it by using kstrtoul instead of parsing word one by one. Fixes: 72e02075a33f ("md: factor out parsing of fixed-point numbers") Signed-off-by: Li Nan --- drivers/md/md.c | 66 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 8e344b4b3444..faffbd042925 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -3767,35 +3767,51 @@ static int analyze_sbs(struct mddev *mddev) */ int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale) { - unsigned long result = 0; - long decimals = -1; - while (isdigit(*cp) || (*cp == '.' && decimals < 0)) { - if (*cp == '.') - decimals = 0; - else if (decimals < scale) { - unsigned int value; - value = *cp - '0'; - result = result * 10 + value; - if (decimals >= 0) - decimals++; - } - cp++; - } - if (*cp == '\n') - cp++; - if (*cp) + unsigned long result = 0, decimals = 0; + char *pos, *str; + int rv; + + str = kmemdup_nul(cp, strlen(cp), GFP_KERNEL); + if (!str) + return -ENOMEM; + pos = strchr(str, '.'); + if (pos) { + int cnt = scale; + + *pos = '\0'; + while (isdigit(*(++pos))) { + if (cnt) { + decimals = decimals * 10 + *pos - '0'; + cnt--; + } + } + if (*pos == '\n') + pos++; + if (*pos) { + kfree(str); + return -EINVAL; + } + decimals *= int_pow(10, cnt); + } + + rv = kstrtoul(str, 10, &result); + kfree(str); + if (rv) + return rv; + + if (result > (ULONG_MAX - decimals) / (unsigned int)int_pow(10, scale)) return -EINVAL; - if (decimals < 0) - decimals = 0; - *res = result * int_pow(10, scale - decimals); - return 0; + *res = result * int_pow(10, scale) + decimals; + + return rv; } static ssize_t safe_delay_show(struct mddev *mddev, char *page) { - int msec = (mddev->safemode_delay*1000)/HZ; - return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); + unsigned int msec = ((unsigned long)mddev->safemode_delay*1000)/HZ; + + return sprintf(page, "%u.%03u\n", msec/1000, msec%1000); } static ssize_t safe_delay_store(struct mddev *mddev, const char *cbuf, size_t len) @@ -3809,10 +3825,14 @@ safe_delay_store(struct mddev *mddev, const char *cbuf, size_t len) if (strict_strtoul_scaled(cbuf, &msec, 3) < 0) return -EINVAL; + if (msec > UINT_MAX) + return -EINVAL; + if (msec == 0) mddev->safemode_delay = 0; else { unsigned long old_delay = mddev->safemode_delay; + /* HZ <= 1000, so new_delay < UINT_MAX, too */ unsigned long new_delay = (msec*HZ)/1000; if (new_delay == 0) From patchwork Thu Apr 27 08:56:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 88154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp134079vqo; Thu, 27 Apr 2023 02:10:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4cYWLQixvxv2PQBXJbK06parAttm5KT2IOFVjIArFOK7vbiBA2ZspLL6Bu08nouVAKaEnO X-Received: by 2002:a17:90b:33ca:b0:247:8b7d:743f with SMTP id lk10-20020a17090b33ca00b002478b7d743fmr1155159pjb.21.1682586618941; Thu, 27 Apr 2023 02:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682586618; cv=none; d=google.com; s=arc-20160816; b=qXt3Q0TemP/97FbqJou0ZSB/TtGrm2+cd9xvkK4YsxkzQc6qtuPCwpnz7XyfKy8Nxf AyBaalK8pygopm745l/fCJ2hC5zsYbrAF8juXGsxYZ4Hv9yWKl4w6N2KnkMVyXibfMLQ WSZrEWUXX9DJu5gUQVLGPYENHr9nzdh0AgYv6Tyh0mOWoct6wATl1einEzPp6IDfA/Kp 2daxdS9aAW4rGs+ybAxgU4NT1qZYM2TQL2ORH3wlHLDiROOun+x68eH3yQ6DPyYj/utp FfyFp6xE8iejvVwxRXDPUvnZ+T/G2yh7tVyMkPlPLp9AlM8UbhOBGa+/QT/DfclHeAnh SUYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jfqi+MHfzaUE74dqAtcL3zUS4UhcOAdRoIqGqQmpUYQ=; b=LxltdyeHZtTd1zJ/PiSyAPjqRO48yWTyK49Pp4gkxm2MOWfmkpOYW4n9zoz2UEDUY2 HjAzoU80Csc7eW1NHLWx/XgKiDNzHxqU3ZWz1aPl6dhg2o8+KuA91FCmxcswhhzV/ZXv ZoWh3oiHy9N/5dFHFVTykYpEidK7aNqBDh4XJyjuBiIMZwfN0tYdh9FZXNFFZhH2/tJU HEuVqGVeL9q6DazBbnEHxifJ3GoK+Z+wk9nmKz/p/nYHusAeOor1gZqIPa6DyHl6ytBm VUqdsJvCNdggdXAD62SXRWufnSqT8xzFncEVJLRDUwhI6/W81z3i91XEVwbMJjWMoJpd fEow== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 194-20020a6301cb000000b005287c9c425csi4747547pgb.407.2023.04.27.02.10.01; Thu, 27 Apr 2023 02:10:18 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243188AbjD0I5Y (ORCPT + 99 others); Thu, 27 Apr 2023 04:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242844AbjD0I5P (ORCPT ); Thu, 27 Apr 2023 04:57:15 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B53B649CC; Thu, 27 Apr 2023 01:57:13 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Q6V3n5Bgyz4f3k6T; Thu, 27 Apr 2023 16:57:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBH_rHjOEpkmCsBIQ--.37560S7; Thu, 27 Apr 2023 16:57:11 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 3/3] md/raid10: fix wrong setting of max_corr_read_errors Date: Thu, 27 Apr 2023 16:56:12 +0800 Message-Id: <20230427085612.1346752-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230427085612.1346752-1-linan666@huaweicloud.com> References: <20230427085612.1346752-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBH_rHjOEpkmCsBIQ--.37560S7 X-Coremail-Antispam: 1UD129KBjvJXoW7CrWDCFWruF13uF43uF4kJFb_yoW8urW7p3 yDAasxZr45J34UAF1DJrWkua4Fy3sYyayjyr95Aw4fX3W3Jr98t3W8Gayjgr1DWF1rt3W3 Xa98Kr4DCa18tFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVj vjDU0xZFpf9x07UKXd8UUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764319946479463593?= X-GMAIL-MSGID: =?utf-8?q?1764319946479463593?= From: Li Nan max_corr_read_errors should not be negative number. Change it to unsigned int where use it. Fixes: 1e50915fe0bb ("raid: improve MD/raid10 handling of correctable read errors.") Signed-off-by: Li Nan --- drivers/md/md.c | 2 +- drivers/md/raid10.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index faffbd042925..a365ed122960 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4484,7 +4484,7 @@ __ATTR_PREALLOC(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_stor static ssize_t max_corrected_read_errors_show(struct mddev *mddev, char *page) { - return sprintf(page, "%d\n", + return sprintf(page, "%u\n", atomic_read(&mddev->max_corr_read_errors)); } diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 4fcfcb350d2b..28cdb2ae0e91 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -2727,7 +2727,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 int sect = 0; /* Offset from r10_bio->sector */ int sectors = r10_bio->sectors; struct md_rdev *rdev; - int max_read_errors = atomic_read(&mddev->max_corr_read_errors); + unsigned int max_read_errors = atomic_read(&mddev->max_corr_read_errors); int d = r10_bio->devs[r10_bio->read_slot].devnum; /* still own a reference to this rdev, so it cannot @@ -2743,7 +2743,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 check_decay_read_errors(mddev, rdev); atomic_inc(&rdev->read_errors); if (atomic_read(&rdev->read_errors) > max_read_errors) { - pr_notice("md/raid10:%s: %pg: Raid device exceeded read_error threshold [cur %d:max %d]\n", + pr_notice("md/raid10:%s: %pg: Raid device exceeded read_error threshold [cur %u:max %u]\n", mdname(mddev), rdev->bdev, atomic_read(&rdev->read_errors), max_read_errors); pr_notice("md/raid10:%s: %pg: Failing raid device\n",