Skip to content

Commit

Permalink
Merge tag 'fs_for_v5.15-rc1' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/jack/linux-fs

Pull UDF and isofs updates from Jan Kara:
 "Several smaller fixes and cleanups in UDF and isofs"

* tag 'fs_for_v5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  udf_get_extendedattr() had no boundary checks.
  isofs: joliet: Fix iocharset=utf8 mount option
  udf: Fix iocharset=utf8 mount option
  udf: Get rid of 0-length arrays in struct fileIdentDesc
  udf: Get rid of 0-length arrays
  udf: Remove unused declaration
  udf: Check LVID earlier
  • Loading branch information
torvalds committed Aug 30, 2021
2 parents 63b0c40 + 58bc6d1 commit a1ca8e7
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 114 deletions.
27 changes: 13 additions & 14 deletions fs/isofs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ struct iso9660_options{
unsigned int overriderockperm:1;
unsigned int uid_set:1;
unsigned int gid_set:1;
unsigned int utf8:1;
unsigned char map;
unsigned char check;
unsigned int blocksize;
Expand Down Expand Up @@ -356,7 +355,6 @@ static int parse_options(char *options, struct iso9660_options *popt)
popt->gid = GLOBAL_ROOT_GID;
popt->uid = GLOBAL_ROOT_UID;
popt->iocharset = NULL;
popt->utf8 = 0;
popt->overriderockperm = 0;
popt->session=-1;
popt->sbsector=-1;
Expand Down Expand Up @@ -389,10 +387,13 @@ static int parse_options(char *options, struct iso9660_options *popt)
case Opt_cruft:
popt->cruft = 1;
break;
#ifdef CONFIG_JOLIET
case Opt_utf8:
popt->utf8 = 1;
kfree(popt->iocharset);
popt->iocharset = kstrdup("utf8", GFP_KERNEL);
if (!popt->iocharset)
return 0;
break;
#ifdef CONFIG_JOLIET
case Opt_iocharset:
kfree(popt->iocharset);
popt->iocharset = match_strdup(&args[0]);
Expand Down Expand Up @@ -495,7 +496,6 @@ static int isofs_show_options(struct seq_file *m, struct dentry *root)
if (sbi->s_nocompress) seq_puts(m, ",nocompress");
if (sbi->s_overriderockperm) seq_puts(m, ",overriderockperm");
if (sbi->s_showassoc) seq_puts(m, ",showassoc");
if (sbi->s_utf8) seq_puts(m, ",utf8");

if (sbi->s_check) seq_printf(m, ",check=%c", sbi->s_check);
if (sbi->s_mapping) seq_printf(m, ",map=%c", sbi->s_mapping);
Expand All @@ -518,9 +518,10 @@ static int isofs_show_options(struct seq_file *m, struct dentry *root)
seq_printf(m, ",fmode=%o", sbi->s_fmode);

#ifdef CONFIG_JOLIET
if (sbi->s_nls_iocharset &&
strcmp(sbi->s_nls_iocharset->charset, CONFIG_NLS_DEFAULT) != 0)
if (sbi->s_nls_iocharset)
seq_printf(m, ",iocharset=%s", sbi->s_nls_iocharset->charset);
else
seq_puts(m, ",iocharset=utf8");
#endif
return 0;
}
Expand Down Expand Up @@ -863,14 +864,13 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
sbi->s_nls_iocharset = NULL;

#ifdef CONFIG_JOLIET
if (joliet_level && opt.utf8 == 0) {
if (joliet_level) {
char *p = opt.iocharset ? opt.iocharset : CONFIG_NLS_DEFAULT;
sbi->s_nls_iocharset = load_nls(p);
if (! sbi->s_nls_iocharset) {
/* Fail only if explicit charset specified */
if (opt.iocharset)
if (strcmp(p, "utf8") != 0) {
sbi->s_nls_iocharset = opt.iocharset ?
load_nls(opt.iocharset) : load_nls_default();
if (!sbi->s_nls_iocharset)
goto out_freesbi;
sbi->s_nls_iocharset = load_nls_default();
}
}
#endif
Expand All @@ -886,7 +886,6 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
sbi->s_gid = opt.gid;
sbi->s_uid_set = opt.uid_set;
sbi->s_gid_set = opt.gid_set;
sbi->s_utf8 = opt.utf8;
sbi->s_nocompress = opt.nocompress;
sbi->s_overriderockperm = opt.overriderockperm;
/*
Expand Down
1 change: 0 additions & 1 deletion fs/isofs/isofs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ struct isofs_sb_info {
unsigned char s_session;
unsigned int s_high_sierra:1;
unsigned int s_rock:2;
unsigned int s_utf8:1;
unsigned int s_cruft:1; /* Broken disks with high byte of length
* containing junk */
unsigned int s_nocompress:1;
Expand Down
4 changes: 1 addition & 3 deletions fs/isofs/joliet.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ uni16_to_x8(unsigned char *ascii, __be16 *uni, int len, struct nls_table *nls)
int
get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode)
{
unsigned char utf8;
struct nls_table *nls;
unsigned char len = 0;

utf8 = ISOFS_SB(inode->i_sb)->s_utf8;
nls = ISOFS_SB(inode->i_sb)->s_nls_iocharset;

if (utf8) {
if (!nls) {
len = utf16s_to_utf8s((const wchar_t *) de->name,
de->name_len[0] >> 1, UTF16_BIG_ENDIAN,
outname, PAGE_SIZE);
Expand Down
5 changes: 2 additions & 3 deletions fs/udf/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "udf_i.h"
#include "udf_sb.h"


static int udf_readdir(struct file *file, struct dir_context *ctx)
{
struct inode *dir = file_inode(file);
Expand Down Expand Up @@ -135,7 +134,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
lfi = cfi.lengthFileIdent;

if (fibh.sbh == fibh.ebh) {
nameptr = fi->fileIdent + liu;
nameptr = udf_get_fi_ident(fi);
} else {
int poffset; /* Unpaded ending offset */

Expand All @@ -153,7 +152,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
}
}
nameptr = copy_name;
memcpy(nameptr, fi->fileIdent + liu,
memcpy(nameptr, udf_get_fi_ident(fi),
lfi - poffset);
memcpy(nameptr + lfi - poffset,
fibh.ebh->b_data, poffset);
Expand Down
44 changes: 22 additions & 22 deletions fs/udf/ecma_167.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ struct logicalVolDesc {
struct regid impIdent;
uint8_t impUse[128];
struct extent_ad integritySeqExt;
uint8_t partitionMaps[0];
uint8_t partitionMaps[];
} __packed;

/* Generic Partition Map (ECMA 167r3 3/10.7.1) */
struct genericPartitionMap {
uint8_t partitionMapType;
uint8_t partitionMapLength;
uint8_t partitionMapping[0];
uint8_t partitionMapping[];
} __packed;

/* Partition Map Type (ECMA 167r3 3/10.7.1.1) */
Expand Down Expand Up @@ -342,7 +342,7 @@ struct unallocSpaceDesc {
struct tag descTag;
__le32 volDescSeqNum;
__le32 numAllocDescs;
struct extent_ad allocDescs[0];
struct extent_ad allocDescs[];
} __packed;

/* Terminating Descriptor (ECMA 167r3 3/10.9) */
Expand All @@ -360,9 +360,9 @@ struct logicalVolIntegrityDesc {
uint8_t logicalVolContentsUse[32];
__le32 numOfPartitions;
__le32 lengthOfImpUse;
__le32 freeSpaceTable[0];
__le32 sizeTable[0];
uint8_t impUse[0];
__le32 freeSpaceTable[];
/* __le32 sizeTable[]; */
/* uint8_t impUse[]; */
} __packed;

/* Integrity Type (ECMA 167r3 3/10.10.3) */
Expand Down Expand Up @@ -471,9 +471,9 @@ struct fileIdentDesc {
uint8_t lengthFileIdent;
struct long_ad icb;
__le16 lengthOfImpUse;
uint8_t impUse[0];
uint8_t fileIdent[0];
uint8_t padding[0];
uint8_t impUse[];
/* uint8_t fileIdent[]; */
/* uint8_t padding[]; */
} __packed;

/* File Characteristics (ECMA 167r3 4/14.4.3) */
Expand Down Expand Up @@ -578,8 +578,8 @@ struct fileEntry {
__le64 uniqueID;
__le32 lengthExtendedAttr;
__le32 lengthAllocDescs;
uint8_t extendedAttr[0];
uint8_t allocDescs[0];
uint8_t extendedAttr[];
/* uint8_t allocDescs[]; */
} __packed;

/* Permissions (ECMA 167r3 4/14.9.5) */
Expand Down Expand Up @@ -632,7 +632,7 @@ struct genericFormat {
uint8_t attrSubtype;
uint8_t reserved[3];
__le32 attrLength;
uint8_t attrData[0];
uint8_t attrData[];
} __packed;

/* Character Set Information (ECMA 167r3 4/14.10.3) */
Expand All @@ -643,7 +643,7 @@ struct charSetInfo {
__le32 attrLength;
__le32 escapeSeqLength;
uint8_t charSetType;
uint8_t escapeSeq[0];
uint8_t escapeSeq[];
} __packed;

/* Alternate Permissions (ECMA 167r3 4/14.10.4) */
Expand Down Expand Up @@ -682,7 +682,7 @@ struct infoTimesExtAttr {
__le32 attrLength;
__le32 dataLength;
__le32 infoTimeExistence;
uint8_t infoTimes[0];
uint8_t infoTimes[];
} __packed;

/* Device Specification (ECMA 167r3 4/14.10.7) */
Expand All @@ -694,7 +694,7 @@ struct deviceSpec {
__le32 impUseLength;
__le32 majorDeviceIdent;
__le32 minorDeviceIdent;
uint8_t impUse[0];
uint8_t impUse[];
} __packed;

/* Implementation Use Extended Attr (ECMA 167r3 4/14.10.8) */
Expand All @@ -705,7 +705,7 @@ struct impUseExtAttr {
__le32 attrLength;
__le32 impUseLength;
struct regid impIdent;
uint8_t impUse[0];
uint8_t impUse[];
} __packed;

/* Application Use Extended Attribute (ECMA 167r3 4/14.10.9) */
Expand All @@ -716,7 +716,7 @@ struct appUseExtAttr {
__le32 attrLength;
__le32 appUseLength;
struct regid appIdent;
uint8_t appUse[0];
uint8_t appUse[];
} __packed;

#define EXTATTR_CHAR_SET 1
Expand All @@ -733,15 +733,15 @@ struct unallocSpaceEntry {
struct tag descTag;
struct icbtag icbTag;
__le32 lengthAllocDescs;
uint8_t allocDescs[0];
uint8_t allocDescs[];
} __packed;

/* Space Bitmap Descriptor (ECMA 167r3 4/14.12) */
struct spaceBitmapDesc {
struct tag descTag;
__le32 numOfBits;
__le32 numOfBytes;
uint8_t bitmap[0];
uint8_t bitmap[];
} __packed;

/* Partition Integrity Entry (ECMA 167r3 4/14.13) */
Expand Down Expand Up @@ -780,7 +780,7 @@ struct pathComponent {
uint8_t componentType;
uint8_t lengthComponentIdent;
__le16 componentFileVersionNum;
dchars componentIdent[0];
dchars componentIdent[];
} __packed;

/* File Entry (ECMA 167r3 4/14.17) */
Expand Down Expand Up @@ -809,8 +809,8 @@ struct extendedFileEntry {
__le64 uniqueID;
__le32 lengthExtendedAttr;
__le32 lengthAllocDescs;
uint8_t extendedAttr[0];
uint8_t allocDescs[0];
uint8_t extendedAttr[];
/* uint8_t allocDescs[]; */
} __packed;

#endif /* _ECMA_167_H */
3 changes: 1 addition & 2 deletions fs/udf/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode,
dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
sfi->fileIdent +
le16_to_cpu(sfi->lengthOfImpUse))) {
udf_get_fi_ident(sfi))) {
iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
brelse(dbh);
return NULL;
Expand Down
13 changes: 11 additions & 2 deletions fs/udf/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,22 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
else
offset = le32_to_cpu(eahd->appAttrLocation);

while (offset < iinfo->i_lenEAttr) {
while (offset + sizeof(*gaf) < iinfo->i_lenEAttr) {
uint32_t attrLength;

gaf = (struct genericFormat *)&ea[offset];
attrLength = le32_to_cpu(gaf->attrLength);

/* Detect undersized elements and buffer overflows */
if ((attrLength < sizeof(*gaf)) ||
(attrLength > (iinfo->i_lenEAttr - offset)))
break;

if (le32_to_cpu(gaf->attrType) == type &&
gaf->attrSubtype == subtype)
return gaf;
else
offset += le32_to_cpu(gaf->attrLength);
offset += attrLength;
}
}

Expand Down
13 changes: 6 additions & 7 deletions fs/udf/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,

if (fileident) {
if (adinicb || (offset + lfi < 0)) {
memcpy((uint8_t *)sfi->fileIdent + liu, fileident, lfi);
memcpy(udf_get_fi_ident(sfi), fileident, lfi);
} else if (offset >= 0) {
memcpy(fibh->ebh->b_data + offset, fileident, lfi);
} else {
memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
-offset);
memcpy(udf_get_fi_ident(sfi), fileident, -offset);
memcpy(fibh->ebh->b_data, fileident - offset,
lfi + offset);
}
Expand All @@ -88,11 +87,11 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
offset += lfi;

if (adinicb || (offset + padlen < 0)) {
memset((uint8_t *)sfi->padding + liu + lfi, 0x00, padlen);
memset(udf_get_fi_ident(sfi) + lfi, 0x00, padlen);
} else if (offset >= 0) {
memset(fibh->ebh->b_data + offset, 0x00, padlen);
} else {
memset((uint8_t *)sfi->padding + liu + lfi, 0x00, -offset);
memset(udf_get_fi_ident(sfi) + lfi, 0x00, -offset);
memset(fibh->ebh->b_data, 0x00, padlen + offset);
}

Expand Down Expand Up @@ -226,7 +225,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
lfi = cfi->lengthFileIdent;

if (fibh->sbh == fibh->ebh) {
nameptr = fi->fileIdent + liu;
nameptr = udf_get_fi_ident(fi);
} else {
int poffset; /* Unpaded ending offset */

Expand All @@ -246,7 +245,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
}
}
nameptr = copy_name;
memcpy(nameptr, fi->fileIdent + liu,
memcpy(nameptr, udf_get_fi_ident(fi),
lfi - poffset);
memcpy(nameptr + lfi - poffset,
fibh->ebh->b_data, poffset);
Expand Down
Loading

0 comments on commit a1ca8e7

Please sign in to comment.