aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-04-19 16:34:50 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:19:17 -0400
commitc3f56102f28d90946171ae51753bd417b003fd42 (patch)
tree7c96c0c4818fa655c6ba4fe61e7de2f1b6915a6a
parentb587398a4ff6520753f9a58da294c80ee22443a5 (diff)
libceph: validate timespec conversions
A ceph timespec contains 32-bit unsigned values for its seconds and nanoseconds components. For a standard timespec, both fields are signed, and the seconds field is almost surely 64 bits. Add some explicit casts so the fact that this conversion is taking place is obvious. Also trip a bug if we ever try to put out of range (negative or too big) values into a ceph timespec. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r--include/linux/ceph/decode.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
index 9575a52e011f..379f71508995 100644
--- a/include/linux/ceph/decode.h
+++ b/include/linux/ceph/decode.h
@@ -154,14 +154,19 @@ bad:
154static inline void ceph_decode_timespec(struct timespec *ts, 154static inline void ceph_decode_timespec(struct timespec *ts,
155 const struct ceph_timespec *tv) 155 const struct ceph_timespec *tv)
156{ 156{
157 ts->tv_sec = le32_to_cpu(tv->tv_sec); 157 ts->tv_sec = (__kernel_time_t)le32_to_cpu(tv->tv_sec);
158 ts->tv_nsec = le32_to_cpu(tv->tv_nsec); 158 ts->tv_nsec = (long)le32_to_cpu(tv->tv_nsec);
159} 159}
160static inline void ceph_encode_timespec(struct ceph_timespec *tv, 160static inline void ceph_encode_timespec(struct ceph_timespec *tv,
161 const struct timespec *ts) 161 const struct timespec *ts)
162{ 162{
163 tv->tv_sec = cpu_to_le32(ts->tv_sec); 163 BUG_ON(ts->tv_sec < 0);
164 tv->tv_nsec = cpu_to_le32(ts->tv_nsec); 164 BUG_ON(ts->tv_sec > (__kernel_time_t)U32_MAX);
165 BUG_ON(ts->tv_nsec < 0);
166 BUG_ON(ts->tv_nsec > (long)U32_MAX);
167
168 tv->tv_sec = cpu_to_le32((u32)ts->tv_sec);
169 tv->tv_nsec = cpu_to_le32((u32)ts->tv_nsec);
165} 170}
166 171
167/* 172/*