Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3337693rdg; Tue, 17 Oct 2023 11:20:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgAjh1gPoEEPlxI5h1DwxfFSKJKnW3kCHpkREqfuFm8KNF137HyK1+hnd05h9Zmklcv9G8 X-Received: by 2002:a05:6359:1a46:b0:143:7cc8:70b1 with SMTP id ru6-20020a0563591a4600b001437cc870b1mr2384359rwb.6.1697566854298; Tue, 17 Oct 2023 11:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697566854; cv=none; d=google.com; s=arc-20160816; b=cEKCSuZKkFQwRBvSUbkgOTVJle3hIBwkpWqce1Yk/BqafFVWl5rlINEVrXRgwZdXp+ wKhZMH+xYtL1uEhIzEf6l1yA9Tq5lFmVMWCkIJP7xULxX0WnhFgei23hQ34ORqd56Ys0 YZFMuaQD6uLiglzaa0zW5xl1Qs2KHki81K4dcu9pjxiwxFCLXVdrDrRKRBF9feRBohz0 7MQJIYnR7955hNjcVedKfdgMMBRfeSy7RzWiLvLapNnjkWBDsSuJrYkWo07tOZhD70Ut uaBGGjHA62flkgilgfilf2879PzlrKzKptuigCe6NjqHUJoX7aaKMNDrGfNIr5w3O2R8 doHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=cogZn6SR2Hrm3xwpZC/9u1+k1saONFiJF3pmAllmSYA=; fh=67vChZdTAG6OnP9Kx3u3dFk+OV/EqynDz46WlHtgB58=; b=FJjCoj6vSIBhaUxlbXYPZsM3bkSlMwPNUQv7uDmtd23ZggX/yu8LRQZiE1ucN/rlD9 /5u7c31Q6To4SHV+Z+EoRGLZ209Y+qe7E0zmxTwSJDYL0n40S1gjG/DElLy18I3OLC0q wzSwGAkuakg83vZYLdmuqeL4fBsC26tAViM8EW64WRACSY2ASGwP57r0UM3KE0kCUE0b QriwT4Z1O8kf8AnYQi86HL94koNCMaiy2qRX5tIZYPEd3xARTGM40foSpqdUxN0YGhhv Zz0MyTkKhMOcbxTqDdFXYhcmqB0TwXVkrSiTtuINojj/SLYWIVZ/XmXqDtiy27tPzx2W LcEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OJ7VhqFY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h5-20020a056a00230500b0068fe9c452acsi2156187pfh.376.2023.10.17.11.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 11:20:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OJ7VhqFY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EFB8A802F227; Tue, 17 Oct 2023 11:20:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344090AbjJQSUi (ORCPT + 99 others); Tue, 17 Oct 2023 14:20:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234954AbjJQSUg (ORCPT ); Tue, 17 Oct 2023 14:20:36 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1503C9F for ; Tue, 17 Oct 2023 11:20:34 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a5995aa42so7799001276.2 for ; Tue, 17 Oct 2023 11:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697566833; x=1698171633; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=cogZn6SR2Hrm3xwpZC/9u1+k1saONFiJF3pmAllmSYA=; b=OJ7VhqFYvc7y9VXkTowPxf9eo2598iYFLcoo6Wz3YzrRqXIjEiaGUk3rX8F6VXXm+V slVA/qE3GARelgEnRMRGwQk/sHypIplRyoP7iFFWNixvhwU2A0LtXmM4kZluRzO1Pn1e ZeuYaUL9s/am4uV6BFk8/+Mpn3FjbCReaQLhVc7M0oUmEkta0414h/A4m61x/K0e6Yq4 OkXgx4YWU1Eux6/Su/4Qk2LCm9Ut5nZquLasFipiIyXSGdR+qGfu+QVUwI5FSBpfLILm xp9iYXjB/RM4CSLcdmCyD2PLiC8xN85JwJliq7VAHUAerhg9Wi0nCVbAoeoy4aRAfgkv 09mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697566833; x=1698171633; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cogZn6SR2Hrm3xwpZC/9u1+k1saONFiJF3pmAllmSYA=; b=I6IVhCObO+9yh5qlmc6PBdU2hRg/BUzuZ/SYUz3FFzCCdc50EXUZJqGP84rTY7zX7e ryXYJtjHMunDUscaSNbRa1QwwCg/n02khhLArg50N2e3wq6b48fCMxxGbWHZVobZNQME DRkVoq2LxYtqUxbCOjlIkV9Ba3mMWb1fbxbNju3+hxeLj4agCZFNv2Bt1Uv//ly+dxQj TEzJtnqnvfbEdTkqTKkFgkp5YFTIeQiHlED3iB2kNQrj7/R93llKujkMIhNpxK+udGEk 82FXj4OKMLuAQv1F6TM/MblwNkLTxwfntnjdznsq5OB/pLnQaqTM8yJTEVzbPMqC6xKO j7Kw== X-Gm-Message-State: AOJu0Yx4726fHiibWVbJWM3AE+Q/9FwJOQJxs0zBpAroP0rumsfqwwlG mA8ZbFJp6cn2jQ5r8mkPFitJPIsjE7o2LPIPmQ== X-Received: from danielmentz2.mtv.corp.google.com ([2620:15c:72:205:c52:2f36:304a:2c97]) (user=danielmentz job=sendgmr) by 2002:a25:6984:0:b0:d8b:737f:8240 with SMTP id e126-20020a256984000000b00d8b737f8240mr61351ybc.0.1697566833277; Tue, 17 Oct 2023 11:20:33 -0700 (PDT) Date: Tue, 17 Oct 2023 11:20:26 -0700 Message-Id: <20231017182026.2141163-1-danielmentz@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Subject: [PATCH] scsi: ufs: Leave space for '\0' in utf8 desc string From: Daniel Mentz To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tomas Winkler , Avri Altman , "Martin K . Petersen" , Daniel Mentz , Mars Cheng , Bart Van Assche , Yen-lin Lai Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 11:20:52 -0700 (PDT) utf16s_to_utf8s does not NULL terminate the output string. For us to be able to add a NULL character when utf16s_to_utf8s returns, we need to make sure that there is space for such NULL character at the end of the output buffer. We can achieve this by passing an output buffer size to utf16s_to_utf8s that is one character less than what we allocated. Other call sites of utf16s_to_utf8s appear to be using the same technique where they artificially reduce the buffer size by one to leave space for a NULL character or line feed character. Fixes: 4b828fe156a6 ("scsi: ufs: revamp string descriptor reading") Reviewed-by: Mars Cheng Reviewed-by: Bart Van Assche Reviewed-by: Yen-lin Lai Signed-off-by: Daniel Mentz --- drivers/ufs/core/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 8382e8cfa414..5767642982c1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3632,7 +3632,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, */ ret = utf16s_to_utf8s(uc_str->uc, uc_str->len - QUERY_DESC_HDR_SIZE, - UTF16_BIG_ENDIAN, str, ascii_len); + UTF16_BIG_ENDIAN, str, ascii_len - 1); /* replace non-printable or non-ASCII characters with spaces */ for (i = 0; i < ret; i++) -- 2.42.0.655.g421f12c284-goog