Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp752444rwd; Tue, 16 May 2023 07:20:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/2NewuoZccUGZrRCkFPrNk7ExFCs7yabc+snMaWOqFrbt+o3jY66TKwd2HFuaD8jtU4+w X-Received: by 2002:a17:902:d3c6:b0:1a9:7e44:17 with SMTP id w6-20020a170902d3c600b001a97e440017mr32866715plb.17.1684246822467; Tue, 16 May 2023 07:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684246822; cv=none; d=google.com; s=arc-20160816; b=DYQlPe0WGiu5nA++kG53AwLidTtEXYwnm75CeCqSoZpEG7CiB25Po+LNiyyWfn3BsO cOb3147y05Kf8qZNKo7baZOK6WSZlP1XI9djYUycqrSgbwCf8hyAFtanVFsZBQuuOHk1 uzgM7wP2PwSwFMApm3IYdYZkGVZvBFQ3KoHOfea1/5Yyaoy/yoUrT1F96lic0tEH3BhX jI7naiNnlF3WA1X48LMj0hxa/0puMyOzpZWpl2X+c3f4wYQ/Rq+9SWPJ9qvFUDssKaIn JokVqIsvHARm1jy4hh/jwj18WcwZ/H4uGbA3ZeGC20lszwVLjKVr64Z6P5V3Sm6feZrV 4Ybg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:mime-version:date:message-id :dkim-signature; bh=twS5ahFzaWXt7vJAdMtEbWdDWzby14zvPLkx6kO9lrM=; b=p/VfcDQKa9f3417f546zCQ6cKhlNdlDOM/SRe4swX0pOObihNSC1FdB65NIYUxObhR uPUi0W20OS8r247tONF95QogPEl6/QldNRYGiH6cQbh/3zMT+t7qZzIaEnnN923qPFgR Szfdmt356BdSpox2c1+7Y1bAPfQLMGnrBwZosWCx/CrB0QHP5DexlCkJsLiVYlSAUMVy JXAAUpt6Lzt1sldKJ7tfuWxzXJdJO8VK2hbDQdRgyQYsgtrVmYjAAkWGR70q9RdCmaxc hpnI8QfzZFMFS09F/Ds4TPrR4noQ74MfkLn0Nuc9vY7fWhs0WxOOvwJtcSLp2Xo9yNfG jtPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EA8sdwwR; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170903120f00b001a1b75674bdsi19330237plh.207.2023.05.16.07.20.05; Tue, 16 May 2023 07:20:22 -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=@redhat.com header.s=mimecast20190719 header.b=EA8sdwwR; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232890AbjEPODf (ORCPT + 99 others); Tue, 16 May 2023 10:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbjEPODd (ORCPT ); Tue, 16 May 2023 10:03:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0208525D for ; Tue, 16 May 2023 07:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684245766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=twS5ahFzaWXt7vJAdMtEbWdDWzby14zvPLkx6kO9lrM=; b=EA8sdwwR/4REOfMAWhhQnD53eFBvL6o2t7W1iBdo/l2xc/EzPRkyXxO1uIB1i8bWbvsdN2 Cj8XgLzwaRCRMQoK73oM9b5iuOYEEyMxBwQxwJzhk3E+7Du+LBqxQ7ETlpaNRFtE8LLU6U M2dS0R37FpF3htRAPUd8zWryOnq7Cyg= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-8YVGO-ovO0iTzm63bW9moQ-1; Tue, 16 May 2023 10:02:38 -0400 X-MC-Unique: 8YVGO-ovO0iTzm63bW9moQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-965cd056598so1697971766b.0 for ; Tue, 16 May 2023 07:02:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684245748; x=1686837748; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:mime-version:date:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=twS5ahFzaWXt7vJAdMtEbWdDWzby14zvPLkx6kO9lrM=; b=J0/Na7IKRO3MpeMWfOgf+xH570CRpZ10aeIm33d3L9I9onAKuHGqzHKH5lVD0c3Woq qpXOWQPJDC3m93cRvAADiDUAguoYEVgGFgfTw72nE1oz5Rp9quI8JD9PD/tKAgRARfWV qbPOUnvhbSY/aMTtigE3e1mCrTZQxGL4Kap/iUkiV6nNURtVqxpv6j8UwE54lkRwbmoT fj7SxJvGR2eu053Ju5ZfEYz7rtR5aK+GbNXxlzkhdPvjcLiNGQcZLGvcr9aODrZNveF6 9ccPfK7zRfdylDUsPkCeg9E+I3WBQVswaGwv+KwmzPMrVETPOsxBa55+CcIEODEEeL4t +uHQ== X-Gm-Message-State: AC+VfDzpCFM06bQzG+9VcOqB1boHxMhnfFgmmy4PClo/XZ6GiZLN1720 7dVfsGArY3lWnMRgSGeFM9ClfYgJBOainaviRAS/uwB7vuCI4HLiIWW0Wc7FkVULzb9nsK/YDj4 5F8kkhHiabSTXeNZ1Kb3cqOPU X-Received: by 2002:a17:907:1687:b0:94e:1764:b0b5 with SMTP id hc7-20020a170907168700b0094e1764b0b5mr40844287ejc.69.1684245748329; Tue, 16 May 2023 07:02:28 -0700 (PDT) X-Received: by 2002:a17:907:1687:b0:94e:1764:b0b5 with SMTP id hc7-20020a170907168700b0094e1764b0b5mr40844264ejc.69.1684245748028; Tue, 16 May 2023 07:02:28 -0700 (PDT) Received: from [192.168.0.5] ([85.13.73.241]) by smtp.gmail.com with ESMTPSA id e17-20020a170906845100b0095844605bb8sm11139221ejy.10.2023.05.16.07.02.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 07:02:27 -0700 (PDT) Message-ID: <24c413e6-75a5-254c-b776-1459da83f86f@redhat.com> Date: Tue, 16 May 2023 16:02:26 +0200 MIME-Version: 1.0 Content-Language: en-MW To: Xia Fukun Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org References: <20230516123719.117137-1-xiafukun@huawei.com> From: Peter Rajnoha Subject: Re: [PATCH v5] kobject: Fix global-out-of-bounds in kobject_action_type() In-Reply-To: <20230516123719.117137-1-xiafukun@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 On 5/16/23 14:37, Xia Fukun wrote: > The following c language code can trigger KASAN's global variable > out-of-bounds access error in kobject_action_type(): > > int main() { > int fd; > char *filename = "/sys/block/ram12/uevent"; > char str[86] = "offline"; > int len = 86; > > fd = open(filename, O_WRONLY); > if (fd == -1) { > printf("open"); > exit(1); > } > > if (write(fd, str, len) == -1) { > printf("write"); > exit(1); > } > > close(fd); > return 0; > } > > Function kobject_action_type() receives the input parameters buf and count, > where count is the length of the string buf. > > In the use case we provided, count is 86, the count_first is 85. > Buf points to a string with a length of 86, and its first seven > characters are "offline". > In line 87 of the code, kobject_actions[action] is the string "offline" > with the length of 7,an out-of-boundary access will appear: > > kobject_actions[action][85]. > > Use sysfs_match_string() to replace the fragile and convoluted loop. > This function is well-tested for parsing sysfs inputs. Moreover, this > modification will not cause any functional changes. > > Fixes: f36776fafbaa ("kobject: support passing in variables for synthetic uevents") > Signed-off-by: Xia Fukun > --- > v4 -> v5: > - Fixed build errors and warnings, and retested the patch. > Please, also check this is still working: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-uevent When I try passing the example line "add fe4d7c9d-b8c6-4a70-9ef1-3d8a58d18eed A=1 B=abc", it doesn't recognize such input anymore and it incorrectly considers it as erroneous. -- Peter